| by Arround The Web | No comments

Learn How to Pull From a Remote Branch in Git

In Git, the “$ git pull” command is utilized to download and merge the remote changes to Git local branches. In simple words, you can say that this command is used to update the local branch with a remote branch. For this purpose, it is required to fetch changes from the remote branch to bring Git’s local branch up to speed.

This study will discuss the procedure for pulling from a remote branch in Git.

How to Pull From a Remote Branch in Git?

To pull from a remote branch in Git, first, move to the Git repository and initialize the repository. After that, list the repository’s content and check the status. Next, add the file to the Git repository and save it to the Git repository using the “$ git commit -m <commit-message>” command. Then, run the “$ git remote add origin <remote-url>” command to add the remote and run the “$ git pull origin <branch-name>” command.

Now, let’s move ahead and implement the above-discussed scenario!

Step 1: Move to Git Repository

At first, run the “cd” command to navigate to Git local directory:

$ cd "C:\Users\nazma\Git\Fetch_Pull"

 

Step 2: Initialize Git Repository

Next, initialize the Git directory through the provided command:

$ git init

 

Step 3: List Repository Content

Now, view the existing content of the current local directory:

$ ls

 

Step 4: Check Status

To check the Git repository status, utilize the following command:

$ git status

 
According to the below output, the new file is added to the repository:


Step 5: Track File

Track the file to the Git repository utilizing the provided command:

$ git add file12.txt

 

Step 6: Git Commit

Next, store the changes to the Git repository using the “git commit‘ command with the “-m” option to commit the required message:

$ git commit -m "first commit"

 

Step 7: Add Remote

Next, execute the “git remote add” command with remote repository name and its repository URL:

$ git remote add origin https://github.com/GitUser0422/Temp_repo.git

 

Step 8: Git Pull

Next, run the “git pull” command to pull the remote branch:

$ git pull origin main

 
It can be seen that the “main” remote command has been pulled successfully:


Step 9: Verify Git Pull

Lastly, verify the performed pull operation by executing the “git pull” command:

$ git pull

 
The given “Already up to date” message shows that operation is performed successfully:


We have explained the easiest procedure to pull from a remote branch in Git.

Conclusion

To pull from a remote branch in Git, first, navigate to the Git local repository and initialize the repository. Next, list the content of the repository and check the status. After that, add the file to the Git repository and save it to the Git repository using the “$ git commit -m <commit-message>” command. Then, add the remote and run the “$ git pull origin <branch-name>” command. This study illustrated the method to pull from a remote branch in Git.

Share Button

Source: linuxhint.com

Leave a Reply