Search code examples
gitmergecommitpull

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)


Solution

  • 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