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

4 Responses to “Git: Tying a Remote Branch to an Existing Local Branch”

  1. Mike Rollins |

    Hey, I’m looking into using Git for some of our projects. Is it proper for more than personal projects (I’m assuming the answer is yes)? Do you know of any good tutorials for it?

  2. ncampbell |

    @Mike – Yes it is very proper for projects outside of personal ones. Just take a look at Github to get an example of some of the companies using Git. Also, the Linux Kernal is being managed entirely in Git (Linus Torvalds was the original author with the purpose of an SCM for the kernel).

    As for tutorials. There are a few places you can look. But, the way I really got involved was just diving in. Once you break your mind of the notion that branches should be reserved for complete code forks rarely to be merged again, you’re well on your way to success. :)

  3. salanio |

    GIT is appropiate for personal projects, the positive of GIT is that it is free, the negative is you get what you pay for. For professional projects, real CM tools like Rational Clearcase is the way to go, but there is a cost, but there is also a marked benefit

  4. ncampbell |

    @salanio – I’d love to hear what _benefit_ you think you derive from dealing with Clearcase. Having dealt with it myself I would almost rather stab myself in the face than ever have to work with it again. And, I know organizations moving away from it because it is such a headache. However, I’m always open to being wrong in my opinions. It has happened before. ;D

Leave a Reply