11 Git Commands I Use Daily

11 Git Commands I Use Daily

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”.

Documentation


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.

Documentation


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.

Documentation


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.

Documentation


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

Documentation


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.

Documentation


7. git push origin

Publish the local commits to the remote repository. Here the repository is “origin”.

Documentation


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.

Documentation


9. git revert

Introduce a new commit to revert a pushed commit with the specified commit hash.

Documentation


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.

Documentation


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

Buy Me A Coffee


My other digital presence:


More Content at abhinavjha07.hashnode.dev/


Your feedback is more than welcome

Did you find this article valuable?

Support Abhinav's Blog by becoming a sponsor. Any amount is appreciated!