awy
awy

Reputation: 5624

git checkout and merge in one command

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.

Upvotes: 11

Views: 15475

Answers (2)

King
King

Reputation: 962

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

Upvotes: 24

CodeWizard
CodeWizard

Reputation: 141956

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 & ... & ...
    

Upvotes: 4

Related Questions