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
AI Thread Summary
In this discussion, a user describes their experience with a local Git repository linked to GitHub. After creating a new branch, making changes, and merging it into the master branch, they find that executing `git status` does not indicate that their local repository is behind the remote repository after a change is made directly on GitHub. The user learns that to check if their local branch is behind the remote, they need to run `git fetch origin` before executing `git status`, which then accurately reflects the status of the local branch in relation to the remote. Additionally, they mention using the Git Graph plugin in Visual Studio Code for visualizing commits and tracking changes, highlighting that it provides a convenient way to see how many commits their local repository is ahead or behind the remote. The conversation emphasizes the importance of using `git fetch` to update local tracking information without merging changes.
Wrichik Basu
Science Advisor
Insights Author
Gold Member
Messages
2,180
Reaction score
2,717
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
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
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top