Git allows performing various operations on the Repositories including the local repositories and remote repositories. The user when downloads a project to work upon, a local repository is created to store a copy of the original project. This local repository stores the changes that are being made by the user. This way, the user can edit the changes before adding them to the main project. Multiple users can perform work on the same project at the same time by using local repositories.
The central repository gets updated every time a user pushes the modifications done on the local repository. These changes do not get updated on the local repository of any other developer that is working on the same project. This might create confusion because different collaborators may end up contributing the same feature in the project. To avoid this, the collaborator updates the local copy on their machine every time before starting the work on their repository. This updation of local copy is done by downloading the recent copy of the project on the central repository. This process of updating the local repository is termed as Pulling or Fetching. Git provides
git pull command and
git fetch command to do the cloning of the central repository into the local repository.
Pull command: Before starting the work on a project, the collaborator needs to clone his local repository with the central repository in order to get the latest copy of the project. This is done by the use of
git pull command. This command updates the local repository immediately after its execution.
git pull <remote> <branch-name>
git pull command is a combination of two other commands which are
git fetch and
Attributes of Pull Command:
Pulling changes from the central repository can be done along with the use of certain attributes that can be used to perform multiple pull operations on the repository. These attributes can be used to perform specific pulls from the repository. These are:
- --no-commit: By default
git pullcommand when called will perform the merging of two branches and then automatically executes the commit operation to create a new commit. But, when the pull operation is called with
--no-commitattribute, only the merging process is performed and the commit operation will not take place.
$ git pull <remote> --no-commit
- --rebase: When a
git pullcommand is called it will merge two branches and will create a separate branch which inherits the changes of both the branches being merged. This will create some confusion among the collaborators as an extra branch will be created. To avoid this confusion, this command is used. It will also create a separate branch that inherits the changes from both the branches but, the branch which is to be merged will be removed from the repository.
$ git pull <remote> <branch-name> --rebase
- --verbose: This
git pullmethod when called with the --verbose attribute, will display all the files and content that is being downloaded with the pull method. This will also print all the details of the merging process done by
$ git pull <remote> --verbose
Fetch Command: This command works just like the
git pull command, but the only difference between the both is that
git fetch command will not perform the merge operation after cloning the repository. This command will update the
remote-tracking branches i.e. the local branches that are stored in the remote repository. It will not update the local copy of the branches. This helps to review the changes that are being downloaded before merging those changes with the local repository.
git pull command, on the other hand, performs fetching and merging both the operations. Hence, the collaborator will not be able to review the changes that are being downloaded.
git pull = git fetch + git merge
Attributes of fetch command:
Fetching changes from the central repository can be done along with the use of certain attributes that can be used to perform multiple fetch operations on the repository. These attributes can be used to perform specific fetch operations from the repository. These are:
- --all: When the fetch command is used with --all attribute, it will fetch all the registered remotes along with their branches in a single call.
$ git fetch --all
- --dry-run:This option will actually do not perform any action on the repository but will give a demo for the test run of the command on the repository. It will output the changes or actions that will take place on the execution of command but will not apply them.
$ git fetch --dry-run
git fetch and
git pull both commands can be used to update the local repository with the central repository by downloading the latest changes from the central repository.
- Pushing changes to a Git Repository
- What is a GIT Repository?
- Overturning Changes In Git
- Setup GitLab Repository On Windows 10
- Creating Repository in GitHub
- How to install, configure and use GIT on ubuntu?
- GIT | An Introduction to Github
- An Ultimate Guide to Git and Github
- Git- Debugging
- Examining Git
- Git - Changing History
- Introduction to Git Branch
- Git-Checkout And Merge
- Git Features
- Bare Repositories in Git
- Working with Git Repositories
- Merge Strategies in Git
- Git | Working with Stash
- Handling repositories with Git remote
- Using Git on CommandLine
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.