Changes made in remote repo are not tracked by Git in local repo

  • Thread starter Thread starter Wrichik Basu
  • Start date Start date
  • Tags Tags
    Local
Click For Summary

Discussion Overview

The discussion revolves around how to track changes made in a remote Git repository from a local repository, specifically focusing on how to receive notifications when the local branch is behind the remote branch. Participants explore various commands and tools to achieve this tracking.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant describes a scenario where their local repository does not indicate when it is behind the remote repository after changes are made directly on GitHub.
  • Another participant suggests using the command git remote show origin to obtain information about the remote status.
  • It is proposed that executing git fetch origin before checking the status can provide the necessary information about updates on the remote without merging.
  • A participant confirms that after fetching, the status command accurately reflects if the local branch is behind the remote branch.
  • One user mentions using the Git Graph plugin in Visual Studio Code to visualize commit differences, indicating a preference for graphical tools over command line for tracking commits.
  • Another participant shares their experience with various IDEs and tools, expressing a preference for command line usage due to past issues with other applications.

Areas of Agreement / Disagreement

Participants generally agree on the need to use commands like git fetch to track remote changes, but there is no consensus on a single best method or tool for monitoring the status of local versus remote branches.

Contextual Notes

Some limitations are noted regarding the commands discussed, particularly that git status alone does not provide information about being behind the remote without prior fetching.

Who May Find This Useful

Users interested in Git version control, particularly those looking for ways to manage and track changes between local and remote repositories effectively.

Wrichik Basu
Science Advisor
Insights Author
Gold Member
Messages
2,186
Reaction score
2,694
TL;DR
How can I set up tracking such that Git can inform me when my local repo is behind the remote?
I have a local repository (let's call it MyRepo) that is linked with Github (origin). The master branch is set to track origin/master using
Bash:
$ git branch -u origin/master

Now I create another branch in my local repo, add a file in that branch, commit the change and merge the branch with master:
Bash:
$ git checkout -b side
$ touch some.txt
$ git add .
$ git commit -m "Added some.txt"
$ git checkout master
$ git merge side
If I execute git status on master, I get the following:
Bash:
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
This is expected. So I push the commit using
Bash:
$ git push -u origin master
and I can see my commit on Github.

Now, I go to Github, select the master branch, add a file (some2.txt) and commit the change. I expect Git to tell me that my local repo is behind origin/master by one commit. But this never happens:
Bash:
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
However, if I execute git pull on the master branch, the changes in Github appear immediately in my local repo.

How can I set up tracking such that Git can inform me when my local repo is behind the remote (i.e. when master is behind origin/master)?
 
Technology news on Phys.org
I'm not sure that you can do that with
Bash:
git status
You can however get this information about the remote with
Bash:
git remote show origin
as explained here.
If you want to locally obtain the information about the updates on the remote, but without merging, then you can also try
Bash:
git fetch origin
and then the local status should contain information about the remote changes.
 
  • Like
Likes   Reactions: Wrichik Basu
S.G. Janssens said:
You can however get this information about the remote with
Bash:
git remote show origin
as explained here.
That works, I have to first execute git fetch origin and then git status:
Bash:
$ git fetch origin
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 684 bytes | 4.00 KiB/s, done.
From https://github.com/WrichikBasu/MyRepo
   80b606a..c6450ad  master     -> origin/master

$ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean
S.G. Janssens said:
If you want to locally obtain the information about the updates on the remote, but without merging, then you can also try
Bash:
git fetch origin
and then the local status should contain information about the remote changes.
That works too!
Bash:
$ git remote show origin
* remote origin
  Fetch URL: https://github.com/WrichikBasu/MyRepo.git
  Push  URL: https://github.com/WrichikBasu/MyRepo.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branches configured for 'git pull':
    master merges with remote master
    side  merges with remote side
  Local ref configured for 'git push':
    master pushes to master (local out of date)
Thanks.
 
I use the Git Graph plugin in Visual Studio Code which shows an overview in terms of commits. I rarely look at diffs at the code level and when I do I use GitHub.

Oh I've just re-read your question: if all you want is to know how many commits your local repo is behind (and ahead of) its remote origin, there is an icon in the status bar that refreshes periodically to show this.

https://code.visualstudio.com/docs/editor/versioncontrol#_remotes
 
pbuk said:
I use the Git Graph plugin in Visual Studio Code which shows an overview in terms of commits.
I generally work on Android Studio and Intellij IDEA. I find it easier to look at the log in command line. I tried using Github desktop once, but made some silly mistake and messed up my first (test) repo. Since then, I have been using Git bash only.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
5K
  • · Replies 14 ·
Replies
14
Views
3K
Replies
5
Views
3K
Replies
16
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 0 ·
Replies
0
Views
2K
Replies
2
Views
3K
  • · Replies 31 ·
2
Replies
31
Views
8K
  • · Replies 11 ·
Replies
11
Views
6K