git fetch changes from ahead upstream and merge them into ahead origin

I forked a repository using github, then cloned it locally on my machine.

git clone https://github.com/username/nasaproject.git

Thus, the local repo has as origin my remote github repo. I also added as upstream the original repository:

git remote add upstream https://github.com/boss/nasaproject.git

Running git branch -a returns:

master
* working_branch
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/working_branch
remotes/upstream/master
remotes/upstream/working_branch

On the local repo, I made several changes, committed and pushed them to the origin. At this stage, my github remote repo showed three commits ahead of the original repo.

Few days later, several changes were committed to the original repo. Github shows:

This branch is 3 commits ahead, 4 commits behind boss:working_branch

I would like to merge these changes to my remote repo. This are the steps I done:

git status
git stash
git fetch upstream
git merge upstream/working_branch
git pull —rebase
git stash pop

The local repo shows:

Your branch is ahead of 'upstream/working_branch' by 3 commits

and

Your branch and 'origin/working_branch' have diverged, and have 7 and 3 different commits each, respectively.

Now, I got confused. How do I update my github repo or origin?

PS: Normally, the below command would do the job.

git push origin working_branch

Because you did a rebase, you would need to do a force push

git push --force origin working_branch

Here's a link to a SO question that does a great job of explaining the issue.

链接地址: http://www.djcxy.com/p/49252.html

上一篇: 在主分支上更新新的提交分支?

下一篇: git从上游提取更改并将它们合并到前端