How To Push Specific Commit/Commits To Git Remote without commands? | All you need to know

 Managing code using source control is an inevitable part of current Software development process. Most of us may be aware of how to push the local changes to remote repository in Git, but there may be situations where we have to choose specific Commits from an existing branch and push it to Git Remote.

What is meant by Pushing Specific Commits To Git Remote?

Let me take an example to explain "Pushing specific commits to Git Remote". 

Git Repository History showing Commits

Above figure shows the history of a branch called "master". In this history you can see different commits out there. Out of those we want to maintain a separate branch in the remote with the commits highlighted in the above figure.

Why do we need it?

Simple reason why we need a separate branch in the remote with the specific commits may be that these commits are associated with a different feature that we are trying to develop and accidently it became part of the main branch. Therefore afterwards if we want to maintain or organize the commits based on different features we may need to group the commits belonging to a specific feature and push it to the Git Remote.

How to Select and Push Specific Commits to Git Remote?

We can accomplish the task of cherry-picking the specific commits and pushing it to remote with the help of Git Commands. But Is there any alternate GUI based approach to accomplish the same?

Steps:


Yes, We can accomplish the same using GUI approach. Lets see how it can be done in Visual Studio.

  • Create a new local branch based on the parent commit "Add .gitignore and .gitattributes"

    Right click on the selected commit and click on "New branch" option, Give
the new branch a appropriate name as shown in the figures below:


        
Select the Git Commit



Creating a new local branch
  • Once its done we can checkout the new branch created and see the history of that branch. It will be as shown in the figure below:
First Git Commit for Git Ignore File


  • Right click on the commits that we want to separate and include in the new branch created, in the Hierarchical order and click on Cherry-Pick as shown in the figure below:
       
Cherry picking Git  commits

  • Once all the commits are cherrypicked we can see those in the new branch created as shown in the figure below:
New Git Branch History


We can push the pending changes/Outgoing Changes to the remote it will create the same branch in the remote as well.


Comments

Popular posts from this blog

Creating RESTful Minimal WebAPI in .Net 6 in an Easy Manner! | FastEndpoints

Step By Step Guide to Detect Heap Corruption in Windows Easily

How to dynamically add Properties in C# .NET?