Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get changes from my trunk into a branch?

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.

like image 662
Rupert Madden-Abbott Avatar asked Sep 05 '10 12:09

Rupert Madden-Abbott


People also ask

How do I Create a branch in trunk?

Select "HEAD revision in the repository" in "Create copy in the repository from" section. [Here actually you create a new branch from a particular trunk revision]. Tick "Switch working copy to new branch/tag". [This will make your working code directory connected with the newly created branch] Then select "OK".

How do I switch from svn to trunk branch?

To switch back, just provide the URL to the location in the repository from which you originally checked out your working copy: $ svn switch http://svn.red-bean.com/repos/trunk/vendors .


1 Answers

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
like image 156
alternative Avatar answered Oct 22 '22 12:10

alternative