Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout and merge in one command

Tags:

git

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.

like image 277
awy Avatar asked Jan 06 '16 11:01

awy


People also ask

Does git checkout do a merge?

Merging Branches in a Local RepositoryTo merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch.

How do I create a new branch and checkout at the same time?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


2 Answers

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

like image 62
King Avatar answered Oct 17 '22 01:10

King


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 & ... & ...
    
like image 26
CodeWizard Avatar answered Oct 17 '22 01:10

CodeWizard