This guide will provide the procedure to push a particular commit to a GitHub remote repository and ignore the previous commits.
How to Push a Particular Commit to a GitHub Remote Repository and ignore Previous Commits?
To push a specific commit to a remote rather than all, implement the below-given steps:
- Move to the required Git repository.
- Check Git reference log history.
- Then, view the remote URLs list.
- List all existing remote/local branches and select one of them.
- Lastly, run the “git push <remote-name> <sha-hash>:<remote-branch>” command.
Step 1: Go to Specific Git Repository
First, run the “cd” command along with the local repository path and navigate to it:
Step 2: View Git Reference Log History
Then, view the Git reference log history by utilizing the “git log .” command:
Here, we have selected the below-highlighted commit which we want to push into the remote:
Step 3: Check Remote URL List
Next, execute the provided command to show the list of remote URLs:
Step 4: Display List of All Branches
Now, view the list of all Git branches, including remote and local, with the help of the “git remote” command and “-a” flag for all:
As a result, all branches will be displayed, and select the desired remote branch. For instance, we have chosen the “remotes/origin/master” branch:
Step 5: Push Specific Commit
Finally, execute the “git push” command to push the specific commit to the GitHub hosting service:
In the above-stated command:
- “origin” is our remote URL name that is used for tracking the remote repository data.
- “894cf22” is the SHA-hash of the particular commit, which we need to push only into the remote repository.
- “master” is the remote branch name in which we want to push specific commit changes.
As a result, our selected single local commit changes are pushed into the GitHub remote repository:
That’s all! We have efficiently pushed a particular commit to a GitHub remote repository and ignored the previous commits.
Conclusion
To push a specific commit to a Git remote repository, first, move to the particular Git repository and then check the Git reference log history, select the desired commit, and copy its SHA-hash. After that, view the remote URLs and list all existing branches. Lastly, run the “$ git push <remote-name> <sha-hash>:<remote-branch-name>” command. This guide elaborated on the process of pushing the desired commit to previous remote commits.