In this blog, we will discuss how to pull specific commits from the Git repository and merge the commits in the Git repository.
How to Pull Specific Commit From Git Repository?
The simple answer to the question, it’s not possible to pull a specific commit from a Git remote repository. But can fetch the latest data from the Git remote repository and then merge it with another branch. To do so, first, navigate to the Git repository and fetch all new data from Git remote repository using the “$ git fetch origin” command. Then, check the log history to view the commit with reference and switch to another branch. Lastly, run the “$ git merge <commit-ref>” command to merge the commits.
Now, let’s implement the stated concept!
Step 1: Launch Git Bash
Search and open up the Git terminal on your system with the help of the “Startup” menu:
Step 2: Navigate to Git Repository
Next, execute the “cd” command to move to the Git local repository:
Step 3: Fetch Origin
Then, fetch the remote(origin) by executing the “git fetch” command:
Here, you can see, the latest version of the remote repository is fetched successfully with all metadata:
Step 4: Check Repository Reference Log History
Check the Git local repository log history using the “git log” command with the “–oneline” option:
Step 5: Switch Branch
Now, execute the “git checkout” with branch name you want to switch:
Step 6: Git Merge Commit
Lastly, merge the commit using its reference and bring all changes to the current repository:
That’s all. We have learned how to merge the commits in the Git repository.
Conclusion
On Git you are permitted to pull a specific commit from a Git remote repository. However, Git permits you to fetch the latest data from the Git remote repository and then merge it with another branch. To merge the commits of two branches, first, move to the Git repository and fetch all updated data from Git remote repository. Then, check log history to view commits and their reference and switch the branch. After that, merge the commits. This blog demonstrated the process of merging the commits in the Git repository.