Git Pull

Git Pull / Pull Request – Git Commands

The git pull command is used to pull a repository.

Pull request is a process for a developer to notify team members that they have completed a feature. Once their feature branch is ready, the developer files a pull request via their remote server account. Pull request announces all the team members that they need to review the code and merge it into the master branch.

The “git pull” command

The pull command is used to access the changes (commits)from a remote repository to the local repository. It updates the local branches with the remote-tracking branches. Remote tracking branches are branches that have been set up to push and pull from the remote repository. Generally, it is a collection of the fetch and merges command. First, it fetches the changes from remote and combined them with the local repository.

The syntax of the git pull command is given below:

Syntax:

$ git pull <option> [<repository URL><refspec>…]

In which:

<option>: Options are the commands; these commands are used as an additional option in a particular command. Options can be -q (quiet), -v (verbose), -e(edit) and more.

<repository URL>: Repository URL is your remote repository’s URL where you have stored your original repositories like GitHub or any other git service. This URL looks like: https://github.com/Repository1/GitExample1.git

To access this URL, go to your account on GitHub and select the repository you want to clone. After that, click on the clone or download option from the repository menu. A new pop up window will open, select clone with https option from available options.

Default git pull:

We can pull a remote repository by just using the git pull command. It’s a default option. Syntax of git pull is given below:

Syntax:

$ git pull

 

Git Pull Remote Branch

Git allows fetching a particular branch. Fetching a remote branch is a similar process, as mentioned above, in git pull command. The only difference is we have to copy the URL of the particular branch we want to pull. To do so, we will select a specific branch.

Syntax: $ git pull <remote branch URL>

Git Force Pull

Git force pull allows for pulling your repository at any cost. Suppose the below scenario:

If you have updated any file locally and other team members updated it on the remote. So, when will you fetch the repository, it may create a conflict.

We can say force pull is used for overwriting the files. If we want to discard all the changes in the local repository, then we can overwrite it by influentially pulling it. Consider the below process to force pull a repository:

Step1: Use the git fetch command to download the latest updates from the remote without merging or rebasing.

$ git fetch -all

Step2: Use the git reset command to reset the master branch with updates that you fetched from remote. The hard option is used to forcefully change all the files in the local repository with a remote repository.

$ git reset -hard <remote>/<branch_name>

$ git reset-hard master

Git Pull Origin Master

There is another way to pull the repository. We can pull the repository by using the git pull command. The syntax is given below:

$ git pull <options><remote>/<branchname>

$ git pull origin master

In the above syntax, the term origin stands for the repository location where the remote repository situated. Master is considered as the main branch of the project.

Pull Request in GIT:

Pull request allows you to announce a change made by you in the branch. Once a pull request is opened, you are allowed to converse and review the changes made by others. It allows reviewing commits before merging into the main branch.

Pull request is created when you committed a change in the GitHub project, and you want it to be reviewed by other members. You can commit the changes into a new branch or an existing branch.

Once you’ve created a pull request, you can push commits from your branch to add them to your existing pull request.

For more Git Related post click here.

  1. Git init Command
  2. Git add Command
  3. Git Commit Command
  4. Git Clone Command
  5. Git Config Command
  6. Git Alias Command
  7. Git Checkout Command
  8. Git Push Command
  9. Git Fetch Command
  10. Git Status Command
  11. Git Revert Command
  12. Git Remove (rm) Command
  13. Git LOG Command
  14. Git Cheat Sheet