Actions: | Security

AllGoodBits.org

Navigation: Home | Services | Tools | Articles | Other

Using topic branches in git to ease integration pain

If you want to participate in most public/FOSS projects using git, you'll want to get comfortable with using topic branches. This is a separate branch for a particular topic, even if you're making trivial changes such as spelling. There are various advantages such as:

In a typical scenario, I have forked a repository on github and cloned my fork locally, added the upstream repo:

git clone git@github.com:dhutty/testproject.git
git remote add upstream https://github.com/<upstream_user>/<repository>.git
git fetch upstream
git merge upstream/master

Checkout a new branch, edit away, commit and push the new branch to the origin:

git checkout -b spelling_fixes
git commit -m'spelling fixes' -a
git push origin spelling_fixes

Then you can either have github create a pull request or git format-patch master.

If your branchwork takes a while and there are upstream commits, then you might want to consider rebasing to keep it to date.

git checkout master
git pull
git checkout spelling_fixes
git rebase master

git rebase --interactive allows you to clean up your own branch to make it more presentable upstream by:

Rebasing will stop to allow you to edit certain messages as you've requested; to continue:

git rebase --continue