简体   繁体   中英

How to update my local repo using git pull without pushing

I have a local branch where I haven't done any changes. Then I do

git checkout anotherbranch
# Switched to branch 'anotherbranch'
# Your branch is behind 'origin/anotherbranch' by 25 commits, and can be fast-forwarded.
# (use "git pull" to update your local branch)

So apparantly I need to pull to get all the latest changes. I do this

git pull origin anotherbranch

I expect now everything to be in sync, but it isn't because

git status
On branch anotherbranch
Your branch is ahead of 'origin/anotherbranch' by 2 commits.
(use "git push" to publish your local commits)

nothing to commit, working directory clean

Is this because the merge part of git pull added another two commits? However these commits does not show when I do git log. Instead on top are two commits made by another author. It feels wrong for me to push his two commits. Actually I don't want to push anything at all but just update my local branch. How can I do this? In case git pull was a mistake how can I revert it without producing alternative realities or other git horrors (I haven't pushed anything, except on another feature branch)

git status
On branch anotherbranch
Your branch is ahead of 'origin/anotherbranch' by 2 commits.
(use "git push" to publish your local commits)

It means that you have 2 commits that are not pushed.

As a best practice is good to run

git fetch

once in a while to get all the server metadata (updated deleted branches, new commits etc)

what is the results of this command:

git log --oneline

it will show you all the log with the commits so yu can see what is the problem

好的,所以在我进行git checkout anotherbranch之前,我需要做git rebase origin / anotherbranch这样做没有错,因为我在私有功能分支上。

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