English 中文(简体)
Alias for "git checkout main_branch; git merge topic_branch"?
原标题:

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
最佳回答

Here is sort of what I mean except it does not 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...

问题回答
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.

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  -
git config alias.thething  !git checkout staging ; git merge $1 

should give you one as

git thething development

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 }

I m forever doing this, especially since on one of our projects we have several subtly different production branches. Deploying a fix/update can make your finger s tired.

For all you Windows bods out there: I ve just created a merge.bat file somewhere in my %path% and it contains:

git checkout %1 && git merge %2 --verbose

then all I do is

merge foo bar

and it runs:

git checkout foo 
git merge bar --verbose




相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签