Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need hg update after hg pull while in git I'm doing only git pull

Tags:

git

mercurial

In git to pull and use the latest changes to my local repository I'm using git pull.

In hg, I also use hg pull but it prints then

run 'hg update' to get a working copy

I do run hg update but I wonder why is this difference from git?

like image 606
Alexander Kulyakhtin Avatar asked Oct 09 '13 11:10

Alexander Kulyakhtin


People also ask

What does HG update do?

Use the command hg update to switch to an existing branch. Use hg commit --close-branch to mark this branch head as closed.

Why is git pull not pulling latest commit?

One explanation would be that the latest commits have been done on another branch, as explained in "Git pull from my public repository not working". The other possibility is for you to be in a detached HEAD mode. That would make any git pull "up-to-date" since you are in any branch.

Does git pull update every branch?

No. git-pull will only ever incorporate changes to your local branch. If you want the updates for each other branch, you'll have to check them out and pull down their updates individually.

Does git pull only update changed files?

git pull, in contrast, is used with a different goal in mind: to update your current HEAD branch with the latest changes from the remote server. This means that pull not only downloads new data; it also directly integrates it into your current working copy files.


2 Answers

The other answers don't actually answer the question, which is: why don't Git and Mercurial work the same? Is there a philosophical difference?

In Mercurial, pull is the opposite of push: it syncs the local repo with a remote repo without touching the working copy. So it's more consistent.

In Git, pull is a fetch plus a merge, or a pull plus an update in Mercurial terms. Usually this is what you want. So it's more efficient.

The Distributed Version Control University talk has a slide at the 4-minute mark that clearly demonstrates the way Mercurial works. Michael Ernst's Version control concepts and best practices has a similar diagram (included below):

Distributed version control

like image 181
Mikel Avatar answered Oct 02 '22 13:10

Mikel


Because git pull internally performs git fetch and git merge, whereas hg pull only does what git fetch does. Just do hg pull -u instead. See also this command equivalence table.

Git fetch and mercurial pull do the same thing. Mercurial fetch and git pull do the same thing.

Of course Mercurial and Git use different data structures internally, so at some point there is a technical difference in the implementation details. If you really care deeply about it, just compare the documentation for hg pull and git fetch. The Git wording is more technical and verbose, but in the end it is the same.

like image 40
sschuberth Avatar answered Oct 02 '22 13:10

sschuberth