Table of contents
- 1. git fetch origin
- 2. git status
- 3. git checkout
- 4. git pull origin <branch name>
- 5. git add <name of the file>
- 6. git commit
- 7. git push origin <branch name>
- 8. git cherry-pick
- 9. git revert <commit id>
- 10. git reset — soft HEAD~1
- 11. git reset — hard HEAD~1
- Show your support by buying me a coffee
- My other digital presence:
This article is for my younger self (or any newbies) for using the git command-line, effectively, with a quick note on how I use the commands.
1. git fetch origin
Pulls all the branches/tags from the repository specified. Here the repository is “origin”.
2. git status
Displays the current branch, the files changed since the previous commit also specifies how far the branch is from its source branch.
3. git checkout
git checkout -b origin/
To create a new branch from a particular source branch. Here “origin” is the default repository.
git checkout — —
When there are local changes made to a file, this command will help discard the current changes thus restoring the original state for the file.
git checkout
Check out the particular branch in the local project.
4. git pull origin
Pulls the changes from the remote branch to the local branch and calls git merge, if the changes are compatible.
The difference here between git pull & git fetch is, that git pull will internally call git fetch and also merge the changes with the local if they are compatible.
5. git add
Once the changes to a few files are done, the git add command can be used to add the files to a particular commit you want to make.
Now, the git status command can be used very conveniently to get the names of the files to add to the commit
6. git commit
git commit -m “message relevant to the commit”
To add the local changes to a commit with a meaningful message specifying the contents of the commit.
7. git push origin
Publish the local commits to the remote repository. Here the repository is “origin”.
8. git cherry-pick
To cherry-pick individual commits/merge commits.
git cherry-pick
To cherry-pick a commit using the commit hash
git cherry-pick -m 1
To cherry-pick a merge commit, the -m option is to specify the parent of the mainline, starting from 1.
9. git revert
Introduce a new commit to revert a pushed commit with the specified commit hash.
10. git reset — soft HEAD~1
Undo 1 local commit without losing the changes in the files.
11. git reset — hard HEAD~1
Undo a local commit and discard the changes in the files.
Thank you for reading🤗 If you have come this far, don't forget to follow & react to this blog.
If you ❤️ My Content! Connect with me on Twitter (abhinav_jha07)
Show your support by buying me a coffee
My other digital presence:
Mail: x3vgi9xr@duck.com
GitHub: akj0712
LinkedIn: abhinavjha07
Telegram: abhinav_kumar_jha
More Content at abhinavjha07.hashnode.dev/
Your feedback is more than welcome