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
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.
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.
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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With