views:

143

answers:

5

In our team we are using a development, staging and a master branch plus branches for issues. With this workflow I find myself doing a lot of the following:

For example in the development branch:

git checkout staging; git merge development

Does anyone have a simple alias for this?

It should be something like:

merge_with master

would do:

git checkout master; git merge previous_branch
A: 
git config alias.thething '!git checkout staging ; git merge $1'

should give you one as

git thething development
Michael Krelin - hacker
Unfortunately, the branch that need the be merge are not always the same.It should be something like:merge_with masterI will add this to the question because the formatting does not work here.would do:git checkout master; git merge previous_branch
Jeroen van Dijk
See the update, I've added the parameter.
Michael Krelin - hacker
I actually got the wrong parameter, but you can move it ;-)
Michael Krelin - hacker
A: 

git merge is always performed on the current branch in case of conflict, so you have to checkout the staging branch first.

However, if linear history is permitted, you can use git rebase development staging.

As Michael said, you can always make an alias.

EDIT: Add this to .git/config will do it

[alias]
    merge_to = !sh -c 'CURRENT=$(git symbolic-ref HEAD) && git checkout $1 && git merge $CURRENT' -
Iamamac
I'm just asking for an alias. I need to merge staging with development. For this I need to type two commands where I think one would be enough :)
Jeroen van Dijk
A: 

Here is sort of what I mean except it does work yet.

branch="$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"; echo "git checkout master; git merge $branch"

First it finds out what the current branch is. Then it uses that to determine which branch to merge with.

So the next thing is to find out how to append an alias argument...

Jeroen van Dijk
A: 
git checkout master; git merge HEAD@{1}

You can assign an alias to that using:

git config alias.mm '!git checkout master; git merge HEAD@{1}'

So that git mm will merge your current branch into master.

Antony Hatchkins
A: 

Thanks for all your help. None of all did exactly what I wanted but did get me in the right direction.

I have added the following to ~/.bash_login. For every git repository "merge_to somebranch" will do git checkout somebranch; git merge previousbranch.

# Git functions to quickly merge branches
# e.g. merge_to staging
function current_branch { ref=$(git symbolic-ref HEAD 2> /dev/null); echo ${ref#refs/heads/} }
function merge_to       { branch=`eval current_branch`; git checkout "$@" && git merge $branch }
Jeroen van Dijk