开发者

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

开发者 https://www.devze.com 2023-03-01 19:04 出处:网络
Assuming I\'ve done the following from c:\\, what is proper way to get the latest code from the remote origin?

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
开发者_Go百科# Now what??? pull or update then pull


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消