I have one master
branch and a new
branch. When I started working on the new
branch I forgot to pull the latest commits, and was 20 commits behind master
. I also committed a couple of changes in the new
branch.
However, I was able to update my new
branch with the other commits from the master
branch by doing:
git checkout master
git pull --rebase
git rebase master newBranch
Then I solved the conflicts and my new
branch was updated with the previous commits.
The problem is that these earlier commits are only reflected in my local version of the new
branch. I see this when typing git log
. When I check out the remote version, it still has the old version because I haven't commited/pushed these old commits. When I check git status
, there is nothing to commit.
How can I get the new branch to get these old commits/changes remotely and not just locally? In other words, how can the remote version have same log/history as my local version of the new branch?
Assuming you have a master and new branch(Where you have all your commits) is created out of master branch.Now if the master branch doesn't have all the commits which are there in the central repository then we need to bring the changes from server to master branch and from master to new. Then we need to bring the local commits on new to master and then do a push from there. The below steps does what is said above:
git checkout master
git pull
git checkout new
git rebase master
git checkout master
git merge new
git push
What you're trying to accomplish can be a bit "dangerous". You have remote branches:
and local branches
When rebasing the local new branch onto the newest origin/master commit, you will be rewriting history. For local work, this is not a problem. If your commits have previously been pushed to a remote, and other developers might have work derived from it, it can cause a lot of head scratching because you now have at least two versions of the same changes.
If you are 100% sure that nobody has any derived work, you can push your local new branch to the server
git push origin new
this will, however, fail because the commit you're trying to push is not a fast-forward merge from the previous origin/new commit. You will need to force the push:
git push origin new -f
The server might prevent you from performing this push, though.
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.