6

Assuming I've done the following from c:\, what is proper way to get the latest code from the remote origin?

# Create repo...
mkdir Test
cd Test
git init
...create files
git add .
git commit -a -m "Init Commit"

# Clone repo...
cd ..
git clone Test TestClone

# Edit original
cd Test
...edit files
git commit -a -m "Init Edit"

# Go back to Clone
cd ..\TestClone

# Get latest code
# Now what??? pull or update then pull
Terry
  • 2,148
  • 2
  • 32
  • 53

3 Answers3

5

Others have told you the short version: just pull. But since you actually asked about `remote update...

remote update is the high level command for "update everything we know from remote(s)." It fetches new branches, it can prune old ones, and it can do this for arbitrary groups of remotes, or all of them. It only updates remote tracking branches (with names like origin/master); it doesn't touch your branches. If this sort of updating is what you want to do, this is the command for you. It's quite common to want to inspect what's out there in a remote, without actually merging any of it into any of your branches, and the ability to prune stale branches is pretty nice too.

If all you want to do is merge the appropriate remote branch into your current one, git pull is the right command. It will update some remote branches in the process, yes, but that's not its primary purpose.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
4

Git will automatically setup the remote origin within your cloned repository, and configure your branches to merge from their equivalents on origin when you pull.

All you'll have to do is git pull in this case.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • @sehe: yup, need ECC memory :) – sehe Apr 29 '11 at 14:30
  • "merge from their equivalents"...I thought (and I'm new to Git) that pull always merged in current branch (regardless of name). git pull was how I understood it. So no matter what branch I was in locally, git pull origin master would pull the master branch from remote origin? – Terry Apr 29 '11 at 15:25
  • @Terry I meant that git will, *at the time you clone*, set your local branches to merge with the "equivalent" remote branches. Later, when you pull, git will merge your current branch with whatever remote branch it's set to track. This is not necessarily the remote branch with the same name (ie the "equivalent"); local branch 'my_feature' could be set to track remote branch 'some-remote/some-other-feature', for example. Sorry for the confusion. – user229044 Apr 29 '11 at 15:35
  • One last question...when you refer to origin (remote) in *any* commands, does it always hit the real remote as opposed to some local copy of the remote? i.e. git diff --name-status master..origin/master - does that hit real origin code or the 'repo' in local directory /remotes/origin/master this is [link](http://book.git-scm.com/3_distributed_workflows.html) that is confusing me on this. – Terry Apr 29 '11 at 15:58
  • @Terry Git will always work with local data. You have to `fetch`/`update remote` to retrieve the latest data from a remote; `pull`, which is equivalent to a `fetch` followed by a `merge`, does this for you. – user229044 Apr 29 '11 at 18:30
  • @meagar - Final question (and I knew fetch, merge, pull even ;))...does a git push (to a remote) do an implicit pull? Googling but not hitting obvious match to answer question. – Terry May 05 '11 at 03:33
  • @Terry No, but the push will fail if the local branch isn't up to date. – user229044 May 05 '11 at 14:41
  • @meagar - Shoot, I didn't specify, I meant `pull` *after* your merge? Meaning, if I do a `push` if successful, am I guaranteed to have the latest code? (typing that I'm thinking not, but coming from a VSS background I'd better ask) – Terry May 06 '11 at 05:52
  • @Terry My answer was accurate, you're thinking about this backwards. It's not a matter of "having the latest code" after a push; the push simply will not work unless you *already* have the latest code. You *must* fetch and merge (aka pull) any changes before submitting your own changes. The merging is *always* done on your machine, never in the remote, so you must always merge in changes from the remote locally before pushing your changes back. – user229044 May 06 '11 at 14:06
1

From reading the git help, I think remote update is like fetch.

git pull combines git fetch and git merge. So doing a git pull will both get the changes from the remote and merge them into your working tree.

You do git fetch when you want to get updates from your remote, but don't want them to mingle with your local changes. This is useful for going offline, checking out a new local branch (that's unrelated to your current branch), and just checking what others are working on.

You would only need to do git remote update for fancy remote manipulation. More discussion in this question.

So for just getting latest, use git pull.

Community
  • 1
  • 1
idbrii
  • 10,975
  • 5
  • 66
  • 107