A network of sites, tools, and technology to bring ideas into reality.

The Digital Tumbleweed

Thoughts and ramblings of an enthusiast

Git: Tying a Remote Branch to an Existing Local Branch

As I was cleaning up my code directory and forking projects to have personal dev branches up on Github, I ran into a problem. I needed to tie a remote branch that I had created to an already existing branch.

So, I had branch already in my list of local branches. I did one of these:

git push ncb000gt master:refs/head/branch

This made the remote branch and then a:

git fetch ncb000gt

Pulled it into my view. Now I have two branches, one local, and one remote. I had changes and commits in the local one that I didn’t want to lose.

I could have tried to solve the issue following the .config method, but instead I decided to do it a different way. Basically by moving/renaming the existing local branch:

git branch -M branch branch_temp

Then, create you local branch that is tracking the remote branch and check it out:

git branch --track branch ncb000gt/branch
git checkout branch

Then all you have to do to maintain the existing commits is merge the code in.

git merge branch_temp

That should be about it.

  • Share/Bookmark