chx
chx

Reputation: 11790

How to merge with rebase?

git checkout featurebranch
git rebase develop
git checkout develop
git merge featurebranch

Does git have a built in command / switch to achieve the same?

Upvotes: 2

Views: 1772

Answers (3)

jthill
jthill

Reputation: 60625

There's a shorter sequence for this,

git rebase develop featurebranch
git checkout -B develop

because the merge is a fast forward, just re-hanging the label, which the checkout -B does.

Upvotes: 3

torek
torek

Reputation: 490128

The short answer is no: Git does not have a "rebase other branch, then merge it" command. You can write a script to do it, but you will have to decide how the script should behave if the rebase stops with a conflict. Note that git rebase has a well-defined exit status: zero means "finished successfully", nonzero means "stopped with merge conflict, or failed entirely".

Upvotes: 1

terryoboy
terryoboy

Reputation: 154

If you're using a shell on Linux, here are a couple things you could do.

Use && to move on to the next command if the previous one is successful:

git checkout featurebranch && git rebase develop && git checkout develop && git merge featurebranch

If you don't want to type that each time and you're working with the same branch each time, you could set an alias in your ~/.bashrc. Just add the following line to your ~/.bashrc file (note: you can change mergeRebaseBranchName to whatever you want):

alias mergeRebaseBranchName='git checkout featurebranch && git rebase develop && git checkout develop && git merge featurebranch'

An alias is sort of like creating a custom command. So now when you type mergeRebaseBranchName in the terminal it will run the commands for you.

Upvotes: 0

Related Questions