Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need a 'remote update' before doing a 'pull' in Git

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
like image 824
Terry Avatar asked Apr 29 '11 14:04

Terry


People also ask

What should I do before git pull?

Always Pull Before a Push Before you try to push code out to the repository, you should always pull all the current changes from the remote repository to your local machine. Doing so will ensure that your local copy is in sync with the remote repository.

Does git pull update remote?

git pull is a Git command used to update the local version of a repository from a remote. It is one of the four commands that prompts network interaction by Git. By default, git pull does two things. Updates the remote tracking branches for all other branches.

What is difference between update and pull in git?

The pull command pulls changes from the parent repository but does not actually make any changes to the files in the repository. Update command is used to actually update the files in the repository.

Does git pull connect to remote?

The git pull command automatically fetches and then merges the remote data into your current branch. Pulling is an easier and comfortable workflow than fetching. Because the git clone command sets up your local master branch to track the remote master branch on the server you cloned.


3 Answers

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.

like image 77
meagar Avatar answered Oct 01 '22 12:10

meagar


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.

like image 38
Cascabel Avatar answered Oct 01 '22 12:10

Cascabel


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.

like image 39
idbrii Avatar answered Oct 01 '22 10:10

idbrii