DEV Community

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

Posted on

4 1

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!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay