I am learning about working with Git remotes by reading the relevant section of the Pro Git Book.
If you clone a repository, the command automatically adds that remote repository under the name "origin". So, git fetch origin
fetches any new work that has been pushed to that server since you cloned (or last fetched from) it.
It’s important to note that the git fetch
command only fetches the data to your local repository; it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when you’re ready.
Here is what I tried. I cloned a repository and edited a file. In the original repository, someone updated the same file and pushed. Then,
I ran git fetch
.
It showed some update progress message. However, git log
did not show that update. Did I misunderstand what git fetch
does? Am I missing something?
I ran git pull
, and I got
error: Your local changes to 'hello_world.c' would be overwritten by merge. Aborting. Please, commit your changes or stash them before you can merge.
Here, I believe it's also merging and to avoid accidental data loss, it aborts.
Edit: Thanks for the answers. Actually before looking at the answers, I was trying myself and realized the same with the following commands / outputs:
$ git ls-remote origin
d0006a6bfa95e0e90aa820a0e50d31a548625652 HEAD
d0006a6bfa95e0e90aa820a0e50d31a548625652 refs/heads/master
$ git ls-remote .
14375458b8a6b84f82d9fa4d2ded0bb8c9e87431 HEAD
14375458b8a6b84f82d9fa4d2ded0bb8c9e87431 refs/heads/master
d0006a6bfa95e0e90aa820a0e50d31a548625652 refs/remotes/origin/HEAD
d0006a6bfa95e0e90aa820a0e50d31a548625652 refs/remotes/origin/master
Also with following commands:
$git log origin --oneline
$git log --oneline
Thank you for bearing with my stupid questions ;-)
By default, git log
shows the log of the current branch. Since fetching without merging doesn't change anything in your current (local) branch, the git log
output doesn't change.
git log
can take the --all
option to show the history of all branches, local and remote. Alternatively, you can explicitly list the remote branch as in git log origin/master
.