by Oliver
19. June 2013 11:39
The scenario I'm facing quite regularly during development is that I want to change to a different feature branch that really someone else is working on to do some maintenance or the like. I know that I can just fast-forward my local branch to the current HEAD of the corresponding remote branch, but using e.g. a GUI such as the wonderful GitExtensions, I have to first check out my local branch and then merge the origin's head into it. This might not only take longer than needed but sometimes lead to problems when the solution is currently open in Visual Studio (depending on the differences between the two branches I'm switching between). Of course, I wasn't the first to want to get around unnecessary overhead, and this stackoverflow answer helped me find a solution to my "problem".
For a branch named "design" simply do the following on a command line inside your repository:
git branch -f design-2 origin/design-2
Git will answer with something like this:
Branch design-2 set up to track remote branch design-2 from origin.
And that's that.
Beware: as stated in a comment of the above mentioned answer, …
Just be very careful not to do that unless you've made absolutely sure the merge would be a fast-forward!
Happy gitting!