TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Git Pull | Pull Request

Git Pull | Pull Request with Git Tutorial, Git Introduction, Git, What is Git, GitHub, What is GitHub, Git vs GitHub, Git Mercurial, Installation of Git for Windows, Installation Git for Ubuntu, Git Environment Setup, Git Command Line Tools, Git Tools, etc.

<< Back to GIT

Git Pull / Pull Request

The term pull is used to receive data from GitHub. It fetches and merges changes from the remote server to your working directory. The git pull command is used to pull a repository.

Git Pull

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 below figure demonstrates how pull acts between different locations and how it is similar or dissimilar to other related commands.

Git Pull

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/ImDwivedi1/GitExample2.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. See the below screenshot:

Git Pull

Copy the highlighted URL. This URL is used to Clone the repository.

<Refspec>: A ref is referred to commit, for example, head (branches), tags, and remote branches. You can check head, tags, and remote repository in .git/ref directory on your local repository. Refspec specifies and updates the refs.

How to use pull:

It is essential to understand how it works and how to use it. Let's take an example to understand how it works and how to use it. Suppose I have added a new file say design2.css in my remote repository of project GitExample2.

To create the file first, go to create a file option given on repository sub-functions. After that, select the file name and edit the file as you want. Consider the below image.

Git Pull

Go to the bottom of the page, select a commit message and description of the file. Select whether you want to create a new branch or commit it directly in the master branch. Consider the below image:

Git Pull

Now, we have successfully committed the changes.

To pull these changes in your local repository, perform the git pull operation on your cloned repository. There are many specific options available for pull command. Let's have a look at some of its usage.

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

Output:

Git Pull

In the given output, the newly updated objects of the repository are fetched through the git pull command. It is the default version of the git pull command. It will update the newly created file design2.css file and related object in the local repository. See the below image.

Git Pull

As you can see in the above output, the design2.css file is added to the local repository. The git pull command is equivalent to git fetch origin head and git merge head. The head is referred to as the ref of the current branch.

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. See the below image:

Git Pull

In the above screenshot, I have chosen my branch named edited to copy the URL of the edited branch. Now, I am going to pull the data from the edited branch. Below command is used to pull a remote branch:

Syntax:

$ git pull <remote branch URL>

Output:

Git Pull

In the above output, the remote branch edited has copied.

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

Consider the below output:

Git Pull

In the above output, I have updated my design2.css file and forcefully pull it into the repository.

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.

Consider the below output:

Git Pull

It will overwrite the existing data of the local repository with a remote repository.

You can check the remote location of your repository. To check the remote location of the repository, use the below command:

$ git remote -v

The given command will result in a remote location like this:

origin  https://github.com/ImDwivedi1/GitExample2 (fetch)
origin  https://github.com/ImDwivedi1/GitExample2 (push)

The output displays fetch and push both locations. Consider the below image:

Git Pull

Git Pull Request

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.

How to Create a Pull Request

To create a pull request, you need to create a file and commit it as a new branch. As we mentioned earlier in this topic, how to commit a file to use git pull. Select the option "create a new branch for this commit and start a pull request" from the bottom of the page. Give the name of the new branch. Select the option to propose a new file at the bottom of the page. Consider the below image.

Git Pull

In the above image, I have selected the required option and named the file as PullRequestDemo. Select the option to propose a new file. It will open a new page. Select the option create pull request. Consider the below image:

Git Pull

Now, the pull request is created by you. People can see this request. They can merge this request with the other branches by selecting a merged pull request.


Next TopicGit Push




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf