Lucas
Lucas

Reputation: 3500

How to push a single commit to a new remote?

I want to push a single commit to a new remote

My local log: A -> B -> C -> D where A is the initial commit

Usual workflow for pushing local repository:

My remote log: A -> B -> C -> D


git push -u origin A:master do not work - why?

Since people are interested for the why
Gitlab don't trigger push event web hooks on the initial commit (not sure if bug or feature..)

Upvotes: 2

Views: 338

Answers (2)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477230

Simply create a new repository:

cd ..
mkdir -p newrepo
git init
cd ../oldrepo
git fast-export master~1..master | (cd ../newrepo && git fast-import && git checkout)

Then add a remote to the second repository:

cd ../newrepo
git remote add origin someremote
git push --all
git remote add old ../oldrepo
git fetch old
git merge old/master
git push

You can of course also filter branches, etc.

Upvotes: 2

Lucas
Lucas

Reputation: 3500

cherry-pick and merge is not the best solution but it works for now.

mkdir newRepo
cd newRepo
git init
git remote add old ../oldRepo
git remote add origin <remote repository>
git fetch old
git cherry-pick <commit SHA>
git push -u origin master
git merge old/master
# merge by hand if neccessary
# git add <manually merged files>
git commit
git rebase
# check result
git log --oneline
git push origin master

Upvotes: 2

Related Questions