Git: things I love and manipulating remote branches
I've been happily using Git for months now. The primary benefit for me has been the ability to work offline without messing with SVK, not having to use the svn commands for renames and moves, the ability to use multiple remote servers and better tools to look at branch level history (think gitk).
Branching is much improved, besides. In Subversion, to branch, you copy the current tree elsewhere and then you work in this branch and finally, merge your changes manually back into trunk (to wit, you have to keep track of what was already merged and not reapply those commits). In git, though, that's all handled for you. Another difference is best illustrated by example: you've started a new feature. Several file modifications later, you look at your diff and realize, "I should have started a new branch for this. doh." With Subversion, there's not much you can do automatically to get these changes into a branch. You'd typically now:
- generate a diff
- undo your changes
- create a branch
- switch to the branch
- apply the diff
- back to work
git branch feature_22.
Sweet, huh?
Well, not altogether. Pushing this local branch to a remote server is altogether too complicated:
git push origin feature_22:refs/heads/feature_22
git fetch origin
git config branch.feature_22.remote origin
git config branch.feature_22.merge refs/heads/feature_22
git checkout feature_22
Sure, you could have created the branch on the remote server first and saved yourself some hassle:
git push origin master:refs/heads/feature_22
git fetch origin
git branch --track feature_22 origin/feature_22
git checkout feature_22
Not exactly straight forward either. Neither are other standard branch related activities. Here's how you delete that remote branch:
git push origin :refs/heads/feature_22 # yeah, that's how you delete a remote branch. :(
git branch -d feature_22 # delete it locally too
Fortunately, Git has a vibrant community that work to abstract away some of these complications. One of my favorite Git tools is git_remote_branch. By using it, working with remote git branches becomes a breeze:
grb publish feature_22 # publish a local branch
grb create feature_22 # create a remote branch and local branch to track it
grb delete feature_22 # delete the remote and local tracking branch
Ah, that's better!

0 comments:
Post a Comment