Question

I've just started using Git and find that whilst I am implementing a feature in a branch, I will encounter some bug that really needs to be pushed to the trunk as soon as possible. In order to do so, I use checkout to switch back to the trunk, make my changes and commit them. I now have a trunk that is bug free.

Unfortunately, my branch needs to have this bug fixed as well. As the feature is not complete, I can't just merge the branch back into the trunk. How can I alter my branch so that it receives the changes I made to the trunk?

If it matters, I am developing on my own and so only have a single repository to worry about.

I am using TortoiseGit so instructions specific to that would be helpful but not necessary.

Was it helpful?

Solution

Make sure you have your branch checked out (git checkout branch-name) and run

git rebase master

And resolve any conflicts that arrive.

If you aren't sure what these commands do, try not using TortoiseGit and use the terminal. It will help you really understand the commands.

WARNING: This assumes a local branch. If you have shared the branch, do not run the rebase (because it modifies history). Run

git merge master

while you are on your other branch. This has less clean history, but can be used.

The difference is:

  • Rebase - rewrites the branch ontop of master, replaying all the changes
  • Merge - a normal merge, creating a commit with two parents

OTHER TIPS

If your repository is not available to anyone else, then git rebase master as suggested above will work.

If your repository is available publicly, you really don't want to rebase since it may screw up others who have cloned your repository. In that case, you want to use git merge master to merge the changes from trunk into your feature branch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top