Open In App
Related Articles

Getting changes from a Git Repository

Improve Article
Save Article
Like Article

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 git merge.
Pulling from a remote repository

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 pull command 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-commit attribute, only the merging process is performed and the commit operation will not take place.

    $ git pull <remote> --no-commit
  • --rebase: When a git pull command 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 pull method 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.

    $ 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

    Hence, 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.

    Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

    Last Updated : 23 Jan, 2020
    Like Article
    Save Article
Similar Reads