Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+13 votes
2 views
in DevOps and Agile by (19.7k points)
edited by

I'm starting to play with Git now and I'm a little bit confused. For me, looks like there are a lot of options to do the same thing. My question, for now, is what is the difference between the commands below:

  • git remote update
  • git fetch
  • git pull

Also which one is more applicable for update a local copy of a remote branch?

3 Answers

+9 votes
by (62.9k points)
git remote update can update all of your branches set to track remote ones, however not merge any changes in.
git fetch can update only the branch you are on, however not merge any changes in.
git pull can update and merge any remote changes of the present branch you are on.
This would be the one you use to update a local branch.
0 votes
by (37.3k points)

Basically all three git commands—git remote update, git fetch, and git pull are used to get changes from a remote repo, but on the local repo, these commands have unique purposes.

Git remote update:

The main purpose of this command is to update your remote-tracking branches, but it does not modify your present working directory, or we can also say the current branch. We can also say that this command fetches changes from all the remotes but not the default one. This command is considered most helpful if we have more than one remote and we want to verify that all the tracking branches are up-to-date.

  1. Git fetch: 

The major difference between git remote update and git fetch is that git fetch downloads objects from another repository without changing our directory, which is currently working, apart from this, it also allows us to see what changes are available before merging them to the current branch.

 

  1. Git pull:

This command is used to fetch or get the changes from the remote and integrate them into your present branch. Git pull is the combination of git fetch and git merge. This command can cause some conflicts if changes in the remote repos have a conflict with your local repos. 

0 votes
by (1.7k points)

1. git fetch

This command downloads updates from a remote repository but does not incorporate them into the master branch. The remote tracking branches get updated, but your current branch remains unchanged.

Usage:

git fetch [name of remote repository]

2. git pull

This command obtains updates from a remote repository and incorporates those changes into the current branch. It indicates that it runs a git fetch operation followed by a git merge operation, but without the user having to issue those commands separately.

Usage:

git pull [remote repository’s name] [branch inside that repository]

3. git remote update

Collects and fetches the required updates from all remotes for every associated remote-tracking branch. It does not affect your current working branch by bringing in any changes.

Usage:

git remote update

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...