Say I did a Git clone from a URL for a repository. I made some changes to a file, did a Git commit.
When I do a git pull, I see that it says "Already up-to-date".
Shouldn’t it show something that says I am not up to date?
My question is:
-
say I did the change above to my local repository, but do not commit for two days, but before the two days are up, someone else had made a change to the remote repository. What steps must I do to ensure I am not overriding changes in the remote repository or at least be able to pull the latest changes before committing?
-
Is there some way to diff between my local repository and the remote repository to check what differences there are? (in case I just want to recall what I had before?)
My first advice is to not
git pull. Do agit fetchfollowed by agit merge.To answer your zero’th question: In fact, you are up-to-date. You have all the commits that the remote repository has. So, there is nothing left to fetch or merge1.
To answer your first question:
git commit: commit your changes on your own branch, totally unrelated to what’s going on in remote repositories.git fetch origin: get the contents of the remote repository (origin), but keep them underorigin/branchbranches. Your own code is unaffected at this point.git merge origin/master: mergeorigin/masterwhich is themasterbranch of the remote repositoryorigin(which you fetched just now) with your current branch.git push origin: push back the commit and the merge to the remote repositoryTo answer your second question:
git fetch origin: updateorigin/branchbranches.git diff origin/master: get the difference between your current branch and the branchorigin/master.1 Suppose this is what the commits in your repository initially look like, on branch
master:This is right after you cloned the repository. Now you say you have made a new commit on your local branch
master:So there are two things to observe here.
Assuming no activity by somebody else in the remote
origin, there is nothing new to fetch. Sogit fetch origin mastertells you there is nothing new.If you do
git merge origin/master, again, there is nothing to merge.origin/masteris a prefix ofmaster. In other words,masteralready contains all the commits thatorigin/masterhas, so there is nothing new to merge.If you had used
fetchandmergeinstead ofpull, you could easily understand which part of the double-command (pull) is the one that results in unexpected (in your opinion) behavior.Of course, after a
git push origin master, you will get: