into - git merge tutorial

How to merge the current branch into another branch (5)

I have two branches, master and dev. I always work on dev and only check code into the master branch once it's been approved for production use. When I do so, I have to do the following:

git checkout master
git merge dev
git checkout dev

That's awfully verbose, and since I do it frequently, I'd like to minimize it. Is there any one git command I can use to merge from my current branch dev to the other branch master without having to checkout the master branch first? Something maybe like:

git merge dev to master

would be awesome. I looked through the git documentation and didn't see anything.

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

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 :)

  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"

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

This is old, but...

Combining the solutions from @kevin-lyda and @dmytrii-nagirniak above. this alias merges the current branch into the specified branch. It uses the remotes method with and uses git commands to get the context.

    merge-to = "!gitmergeto() { git push \"`git rev-parse --show-toplevel`\" `git rev-parse --abbrev-ref HEAD`:$1; } && gitmergeto"

To be used like:

git merge-to other-branch-name

Your best bet would be to just use an alias, placed in your global gitconfig (~/.gitconfig):

    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