tortoisegit working with branches and merging with origin

user1929393 picture user1929393 · Feb 20, 2013 · Viewed 14.9k times · Source

I would like to know what is the best way to merge 1 changed file in your branch back to the source origin branch, but do not want to push all the changed files, as I have many changed files not ready to be merged. For example, can I push just 1 changed file to merge, instead of 3 files that have changed from my branch. Is there a way to set the ones you do not want to merge to a specific setting in tortoisegit?

Answer

Wilbert picture Wilbert · Feb 20, 2013

Yes, it's possible.

First, you should create a local branch that exactly mirrors the remote origin branch. I will tell you the command line commands, but of course you can also use Tortoise Git. We use 'tmp' as name for the temporary local branch, 'src' as the local branch you are currently working with and assume the remote branch name is remotebranchname.

$ git fetch origin
$ git branch -b tmp origin/remotebranchname

Next, you get the single changed file. If you made a nice, single commit with the changes for that file, you can use 'cherry-pick' to only transfer this one commit. I will assume you did not make those changes in a single commit, therefore we make a new one:

$ git checkout src mychangedfile

This will fetch the changed file into your tmp branch. Now you can make a new commit, and finally you can push this branch to origin/remotebranch.

On a side note, I would recommend you to try out Git Extensions. I feel that working with Git in Windows is easier using Git Extensions than Tortoise Git.