简体   繁体   中英

Git how to solve This branch is X commits ahead, X commits behind master

I have a Git repo with a dev and a master branch. I'm adding new stuff on the dev branch and do commit those. So far so good, but I get the info that

This branch is 5 commits ahead, 12 commits behind master.

So what am I supposed to do now?

Basically I want to merge the master into the dev branch without losing the newly added changes to the dev branch, and then merge all changes into the master branch.

Can someone help me out?

As with most things in git you a have a couple options

Merge master into your dev branch

git fetch origin master   
git checkout dev
git merge origin/master
git checkout master
git merge dev

Rebase dev ontop of current master

git fetch origin master
git checkout dev
git rebase origin/master
git checkout master
git merge --no-ff dev

The rebase will look cleaner in your history.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM