How to merge the current branch into another branch
1. Add a remote alias for your local repository, ex:
git remote add self file:///path/to/your/repository
(Or on windows git remote add self C:\path\to\your\repository
)
2. Push to the self remote, ex:
git push self dev:master
The current highest-voted answer by @zerome is a good one, but is a bit needlessly verbose.
In the base of your git repo you can just do this: git push . dev:master
A more generalised solution that would work anywhere in the tree would be:
git push $(git rev-parse --show-toplevel) dev:master
Your best bet would be to just use an alias, placed in your global gitconfig (~/.gitconfig
):
[alias]
merge-to = "!f() { git checkout $1 && git merge $2 && git checkout -; }; f"
so that you can invoke it from any repository as
git merge-to master dev
A little modification from Jefromi alias that doesn't require you to type in the current branch.
So you use it like: git merge-to dev
.
This will switch over to the dev
branch, merge it with CURRENT and then will switch back.
For example, assuming you are on master
branch, it will merge the master into dev and you will still be on the master.
It definitely goes to my dotfiles :)
[alias]
merge-to = "!gitmergeto() { export tmp_branch=`git branch | grep '* ' | tr -d '* '` && git checkout $1 && git merge $tmp_branch && git checkout $tmp_branch; unset tmp_branch; }; gitmergeto"