Git: How to check if a local repo is up to date?

2019-01-30 23:43发布

I would like to know if my local repo is up to date (and if not, ideally, I would like to see the changes).

How could I check this without doing git fetch or git pull ?

9条回答
别忘想泡老子
2楼-- · 2019-01-31 00:11

Not really - but I don't see how git fetch would hurt as it won't change any of your local branches.

查看更多
Lonely孤独者°
3楼-- · 2019-01-31 00:18

Try git fetch --dry-run The manual (git help fetch) says:

--dry-run
Show what would be done, without making any changes.
查看更多
Summer. ? 凉城
4楼-- · 2019-01-31 00:18

This is impossible. How can you know whether or not the repository is "up-to-date" without going to the remote repository to see what "up-to-date" even means?

查看更多
孤傲高冷的网名
5楼-- · 2019-01-31 00:22

you can use git status -uno to check if your local branch is up-to-date with the origin one.

查看更多
萌系小妹纸
6楼-- · 2019-01-31 00:23
git remote show origin

Result:

HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date) <-------
查看更多
霸刀☆藐视天下
7楼-- · 2019-01-31 00:27

First use git remote update, to bring your remote refs up to date. Then you can do one of several things, such as:

  1. git status -uno will tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same.
  2. git show-branch *master will show you the commits in all of the branches whose names end in 'master' (eg master and origin/master).

If you use -v with git remote update (git remote -v update) you can see which branches got updated, so you don't really need any further commands.

查看更多
登录 后发表回答