9

Is there a way to say this more concisely?

git checkout master
git merge branch

What I actually want to do much of the time is:

git rebase master branch
git checkout master
git merge branch

Answer https://stackoverflow.com/a/12343727/313842 sort of touched on this but leaves branch checkout out. git merge in one command is also a similar but different question.

Community
  • 1
  • 1
awy
  • 5,271
  • 5
  • 23
  • 28
  • 6
    `git checkout master && git merge branch` ;-) – Tim Jan 06 '16 at 11:19
  • 1
    Maybe you can create a script or symlink which bundles together some Git commands. – Tim Biegeleisen Jan 06 '16 at 11:25
  • Sure I can write a script, or whatever. I just wanted to see if there was a way, which I had missed, to do it with a single command. – awy Jan 07 '16 at 14:34
  • 1
    In the scenario you describe you can do `git checkout -B master`. It performs a `reset` instead of a (fast-forward) `merge`, but that's safe since you did a `rebase master` first. This solution is also mentioned in an alternative answer to the one you linked to. – lenz May 30 '16 at 19:28
  • That is a neat idea - saves one step. Thanks. – awy Jun 01 '16 at 06:42

2 Answers2

22

If your branch names are generally long, and you constantly merge the branch you just checkout from, you can use:

checking out from branch you want to merge

git checkout branch
git merge -

the '-' is shorthand for the previous branch, very handy for quick checking out and merging

Aakash
  • 21,375
  • 7
  • 100
  • 81
King
  • 827
  • 2
  • 10
  • 20
4

You have several options:

  • Script
    Write a script which execute your commands
  • git alias
    Write it in an alias or function inside your .gitconfig file
  • Use & operator

    git checkout master && git merge branch & ... & ...
    
CodeWizard
  • 128,036
  • 21
  • 144
  • 167