When any content of the remote repository is updated, and the git user requires to pull the updated content from the remote repository to the local repository, then the `git pull` command is used. This command is used to fetch and download the required content from the remote repository and update the local repository to keep the repository up-to-date with the remote repository. `git pull` command performs the functions of the other two commands of git. These are `git fetch` and `git merge`.  At first, the `git pull` command downloads the required content from the remote repository like `git fetch,` and next merges the downloaded content with the local repository like `git merge`.

Syntax

git pull [] [ […​]]

Git Merge Options

The pull command has many options related to merging. Some common options are described below.

Option Purpose
–commit It is used to commit the result after the merge, and it can be used to override –no-commit.
–edit, -e It is used to open an editor before committing the merge to edit the auto-generated merge message.
–ff It is used to resolve the merge quickly, which means the branch pointer is used to match the merged branch but doesn’t create any merge commit.
–no-ff  It is used to create a merge commit in all cases of the merge.
–ff-only It is used to resolve the merge as a fast-forward if possible otherwise, refuse the merge and exit with a non-zero status.
–signoff It is used to add the signed-off-by-line by the committer at the end of the commit message.
–no-signoff It is used to don’t add the signed-off-by-line.
–stat It is used to display a diffstat at the end of the merge.
-n, –no-stat It is used to don’t display the diffstat at the end of the merge.
–overwrite-ignore It is used to overwrite the ignored files from the merge result. This is the default behavior.
-r, –rebase [=false|true|merges|preserve|interactive] It is used to change the base of the branch from one commit to another that acts like the branch is created from a different commit. Different types of values can be assigned for this option.
-v, –verbose It is used to print the description of all recognized commands.

The pull command has many options related to fetching. Some common options are described below.

Option Purpose
–all It is used to fetch all remote content.
 -a, –append It is used to append the ref names and object names of fetched refs to the existing contents of .git/FETCH_HEAD.
–depth= It is used to limit the fetching to the particular number of commits from the remote branch history.
–dry-run It is used to display what would be done without making any changes.
 -f, –force It is used with : refspec to refuse the update of the local branch.
-k, –keep It is used to keep the downloaded pack.

Prerequisites

1. Install GitHub Desktop.


GitHub Desktop helps the git user to perform the git-related tasks graphically. You can easily download the latest installer of this application for Ubuntu from github.com. You have to install and configure this application after download for using it. You can also check the tutorial for installing GitHub Desktop on Ubuntu to know the installation process properly.

2. Create a GitHub account


You will require to create a GitHub account to check the commands used in this tutorial.

3. Create a local and a remote repository with the same name


The output of the git pull command will be applied based on the remote and local repository.

Pull the content using –rebase option

Select any remote repository from github.com. Here, a remote repository named send-email-php has been used for checking the pull command.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/git-pull-remote-repository-01.png" data-lazy- height="581" src="data:image/svg xml,” width=”1039″>

Run the following commands to check the list of the files and folders of the current location and pull the content of the particular remote repository to the local repository. Here `ls` command will be executed before executing the pull command and after executing the pull command. You have to provide your username and password of the GitHub account to execute the pull command.

$ ls


$ git pull –rebase https://github.com/fyc21/send-email-php


$ ls

The following output will appear after executing the above commands. The output shows that send-email.php has been downloaded from the remote repository.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/git-pull-remote-repository-02.png" data-lazy- height="214" src="data:image/svg xml,” width=”1039″>

Pull content using –verbose option

Modify the content of the send-email.php file from the remote repository and commit the task with a new commit message.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/git-pull-remote-repository-03.png" data-lazy- height="585" src="data:image/svg xml,” width=”1039″>

Run the following command to pull the changed content of the remote repository to the local repository.

The following output will display after executing the above command. It shows that a file has changed, a new file has been inserted, and the old file has been deleted.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/git-pull-remote-repository-04.png" data-lazy- height="285" src="data:image/svg xml,” width=”1039″>

You can open the file from the local repository and remote repository to check that the content of the file has been updated properly in the local repository. Run the following command to read the content of the send-email.php.

The following output shows the content of the send-email.php file from the local repository.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/git-pull-remote-repository-05.png" data-lazy- height="175" src="data:image/svg xml,” width=”1039″>

The following image shows the content of the send-email.php file of the remote repository.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/git-pull-remote-repository-06.png" data-lazy- height="593" src="data:image/svg xml,” width=”1039″>

The content of the multiple remote repositories can be pulled to the local drive by using the command, `git pull origin` or `git pull upstream`. If any local repository is opened in the GitHub Desktop and the corresponding remote repository is updated remotely, you will get the Pull origin option in the GitHub Desktop application image after fetch.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/git-pull-remote-repository-07.png" data-lazy- height="531" src="data:image/svg xml,” width=”1039″>

Conclusion

The uses of the `git pull` command to pull the content from the remote repository by using different options of pull command have been explained in this tutorial with a demo remote repository. I hope that the readers will pull the content from the remote repository after reading this tutorial.

About the author

<img alt="Fahmida Yesmin" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/05/echo/channel-logo-150×150.jpg609fd222670f0.jpg" height="112" src="data:image/svg xml,” width=”112″>

Fahmida Yesmin

I am a trainer of web programming courses. I like to write article or tutorial on various IT topics. I have a YouTube channel where many types of tutorials based on Ubuntu, Windows, Word, Excel, WordPress, Magento, Laravel etc. are published: Tutorials4u Help.