简体   繁体   中英

Git repo branching mistake fix

I was trying to create a new branch from the master branch of my organization repository, and yet when I checked how this branch was, I found that it was some commits behind the master branch. I found that I had forgot to do a pull into my branch before creating that branch. Should I contact the admin of the repository before resetting it to the correct state, and what are the commands I should perform to get it in line with the latest commits?

This command should rebase your current branch on top of the local master branch:

$ git rebase master

This assumes you pulled the changes on master already. Alternatively you can rebase directly on top of the remote branch after fetch:

$ git rebase origin/master

This assumes your remote is called origin (which is often the case).

make sure you checkout into master and pull the changes using:

git pull 

rebase with master

git rebase origin/master -i

force push your branch using

git push origin <your branch> --force

click on your commit to check that no files are different in your branch from master

The other two answers are correct.

If you just created your branches, then you could also just delete them and start over.

To delete your remote branch:

git push origin --delete <your branch>

to delete your local branch:

git branch -D <your branch>

You shouldn't need to contact the Administrator to delete branches that you created.

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