简体   繁体   中英

Git and Github with branches

I seem to have created a mess. In my local repo, I have the following structure:

在此处输入图片说明

I have a clean set of code in my master. And to do some new experiments, I forked it to rsadev. I am planning to go back to Master and fork again to another branch soon.

In my github repository, it looks like this: 在此处输入图片说明

Looks like both my master and my rsadev are at the last latest commit (which should be only on the rsadev branch). How can I get my remote repository to follow my local one? Please help me get out of this mess.

Please also note that I work on different laptops/servers. So my workflow is like this:

1) On my current machine, I do a git pull for the latest repository. 2) I make changes 3) Do a git push at the end of the day.

Please let me know if I need to take care of anything when moving between computers.

Thanks

If local master is pointing to the correct commit, and you want the same on the remote repo, then run the following to force-update the remote (note this will mess up the history on the remote, so anyone following or forking is going to be confused!)

git checkout master
git push origin master --force

(You may need to git stash if you have uncommitted changes in rsadev to be able to checkout master ).

It looks like rsadev branch and remote master are pointing to the same commits. This means you made the commits to master at some point and pushed to remote (from another machine apparently, as your local master is behind).

If I understand you correctly, you want remote master point to the same commits as your local. In that case you'd have to rewrite history. Investigate this is what you want (if other people are using remote repo, this might be problematic), and if you are sure, you can do git push origin master --force . Note the use of force.

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