tags:

views:

73

answers:

3

When I want to merge one branch to another I use to do the following(in this example master to custom):

git checkout master && git pull && git checkout custom && git merge master

Can somebody suggest how to simplify this?

Thanks, Bogdan.

A: 

use a shell script

Jay
+3  A: 

git checkout custom && git pull origin master

Ken Bloom
Assuming, of course, that the local branch *master* was pulling from remote branch *master* on the remote *origin*. This is likely to be the case if the local repository was a simple clone of a repository with a *master* branch as its HEAD, but it is not always true.
Chris Johnsen
This does something different to the recipe in the original question. In the original question origin's master is merged into the local master and the the result of that merge is merged into custom. These only do the same thing if the first merge was a fast-forward. Also this sequence doesn't update the local master branch.
Charles Bailey
+2  A: 

It can not be simplified in the general case. Both the merge and the pull (which uses either a merge or a rebase) might need a working tree to allow the user to resolve potential conflicts.

There may be some simplifying assumptions that you can make though.

If your local master never has any local changes (i.e. every pull into your local master will always be a “fast-forward” update; possibly because the only reason you have a local master is because git clone automatically made one for you), then you can probably just ignore your local master and re-configure your local custom to pull from the same upstream that your local master uses.

# copy "upstream" config from 'master' to 'custom'
for o in remote merge rebase mergeoptions; do
    v="$(git config branch.master."$o")" && 
      git config branch.custom."$o" "$v"
done

Then, to merge the upstream into custom just do git checkout custom && git pull.

Alternatively, you could work directly on your local master (move your custom commits to master with git checkout master && git reset --hard custom, then you could abandon or delete custom).

Chris Johnsen