afraid.jpg afraid.jpg - 9 months ago 104
Git Question

git how to confirm that l am behind the git repository

l can use

git status
to confirm what file l modified locally, but l don't know how to confirm that l am behind the git repository.

l always find out it when l push my code to git, or
git pull
before
git push
anytime. but l think it's not a smart way. l tried to google, but found nothing(maybe keywords' problem)

git add .
git commit -m "xxx"
git push
! [rejected] master -> master (fetch first)
error: failed to push some refs to
'[email protected]/xxxx'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Answer Source

The usual way to answer this question locally is to do a git fetch. This will update the local tracking branch origin/master, which is what Git uses locally to figure out whether your local master branch is ahead or behind of the true remote master branch. So all you need to do here is the following:

git fetch origin
git status

You might see output looking something like the following:

This branch is 2 commits ahead and 2 commits behind master

If this were your status, it would imply that you had made two commits since the point when you last synched. And it would also mean that other people had laid down two commits to the remote master branch since the last sync.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download