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

  • Thread starter Wrichik Basu
  • Start date
  • Tags
    Local
In summary, if you want to locally obtain the information about the updates on the remote, but without merging, then you can also try git fetch origin and then the local status should contain information about the remote changes.
  • #1
Wrichik Basu
Science Advisor
Insights Author
Gold Member
2,138
2,713
TL;DR Summary
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
  • #2
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 Wrichik Basu
  • #3
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.
 
  • #4
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
 
  • #5
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.
 

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

Why are changes made in the remote repo not tracked by Git in the local repo?

Git is a distributed version control system, meaning that each local repo is a complete copy of the remote repo. However, changes made in the remote repo are not automatically synced to the local repo unless the user manually pulls those changes.

How can I track changes made in the remote repo in my local repo?

In order to track changes made in the remote repo, you need to use the git pull command to fetch and merge the changes from the remote repo into your local repo. This will update the files in your local repo to match the current version in the remote repo.

Can I track changes made in the remote repo without pulling them into my local repo?

Yes, you can use the git fetch command to retrieve the changes from the remote repo without automatically merging them into your local repo. This allows you to review the changes before deciding whether to merge them into your local repo.

Why do I need to pull changes from the remote repo into my local repo?

Pulling changes from the remote repo into your local repo ensures that your local copy is up to date with the latest changes made by other collaborators. This allows for better collaboration and avoids conflicts when merging changes.

Is there a way to automatically track changes made in the remote repo in my local repo?

Yes, you can use the git pull --rebase command to automatically fetch and merge changes from the remote repo into your local repo. This will rebase your local changes onto the latest version in the remote repo, keeping your commit history linear and avoiding unnecessary merge commits.

Back
Top