DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for My list of useful git commands
Theodore Karropoulos
Theodore Karropoulos

Posted on

My list of useful git commands

As all those of us involved in the field of Computer Science know or should know, Git is by far the most widely used modern version control system in the world today. We utilized it in our everyday routine to keep track of our code changes and helps us to work with other developers simultaneously and independently.

Although modern IDE and various tools provided by GitHub, Atlassian and other provide us an easy to use way to perform many git commands nothing compares to the power a terminal provides. Bellow you can find a list of my top git commands.

Rename latest's commit message

# This will pop up an editor window allowing us to pass the new commit message
git commit -amend 

# This will not pop up the editor
git commit -amend -m "Your new commit message"
Enter fullscreen mode Exit fullscreen mode

Add file(s) into the latest commit. This requires that last change is not yet pushed into remote

# Add the file
git add the_file_you_want_to_add
# Amend without changing commit message
git commit --amend --no-edit
Enter fullscreen mode Exit fullscreen mode

Reset to specific commit hash and discard any changes since that hash

git reset --hard <commit-hash>
Enter fullscreen mode Exit fullscreen mode

Apply a commit from one branch to another

git cherry-pick <commit-hash>
Enter fullscreen mode Exit fullscreen mode

Show commit logs and limit the output

git log -n <number>
# example git log -n 3
# or
git log -<number>
# example git log -3
Enter fullscreen mode Exit fullscreen mode

If you are aware of any useful / useful git command and want to share it please do not hesitate to leave a comment!

Top comments (0)

Here is a post you might want to check out:

Regex for lazy developers

regex for lazy devs

Sorry for the callout πŸ˜†