Friday, October 14, 2016

Git Tricks: Working in the Wrong Branch

One of the tricky things about Git is getting into the mindset that a branch is a snapshot of files rather than a diff of a file system.

Another tricky thing is remembering to switch before starting to code.

One thing that's tripped up a few of my team members (and myself too!) is what to do when coding in the wrong branch. If they haven't committed, this is easily solved:
Simply switch between branches. The uncommitted files will be unaffected.
The main thing to watch out for is when a changed version of that file is on the branch being switched to. At that point, manual merging needs to happen. But for the general case, it's as easy as pointing your local repository at the desired branch.

No comments:

Post a Comment