mixtly87
mixtly87

Reputation: 1715

Move commits from one git repo to new git repo

Is it possible to move git commits to new (empty) repository?

I will be given link to git repo but meanwhile I want to commit to local repo. Once remote repo is created, I would like to move all commits from local repo to remote one. I have gut-feeling cheery-pick could somehow help, but I'm not sure how. Can it be done?

Upvotes: 0

Views: 87

Answers (2)

MythWTS
MythWTS

Reputation: 166

Once you push your local repo to the remote one, all the commits you have done locally will be pushed (transferred, copied, replicated) to the remote repo, no need to do anything special. Once you get the link to the remote repo just add it as a remote: git remote add alias url replacing alias with something you'll remember (a name for the remote, usually origin is used by default if nothing is specified) and replace url with the usrl of the remote repo. After that, push your commits to the remote using: git push -u alias local-branch-name:remote-branch-name where: alias - the alias you used in previous command local-branch-name the name of the local branch (use master if not sure) remote-branch-name: the name of the branch in the remote repo (usually should be the same not to confuse yourself, again, usually master in the beginning). In short, assuming your commits where to master and the remote repo was at http://some.url.com/code, your commands will be:

git remote add origin http://some.url.com/code
git push -u origin master:master

Upvotes: 1

vvondra
vvondra

Reputation: 3162

There is no trick to this. Git is decentralized, so you just add the new repo as a remote and push to it.

In case it was a completely different working tree, you'd have a problem deciding what is the history of master, but since it's empty, you'll just do:

git remote add new-upstream-name git://url....
git push new-upstream-name master

Upvotes: 1

Related Questions