Tech

Everyday Git Commands

Published
Published:
Table of Contents

Git has hundreds of commands. The good news is you only need about eight for daily work. Here they are, with what they actually do.

Checking what is going on

git status

Shows what has changed and what is ready to commit. When in doubt, run this. I probably run it more than any other command.

git log --oneline

Shows the history of commits, one per line.

Saving your work

git add .
git commit -m "Describe what you changed"

add chooses which changes to include, and commit saves them as a snapshot. Keep the message short and clear — future you will be grateful.

Sharing with others

git push       # send your commits online
git pull       # get the latest commits from others

Working with branches

git branch feature-x      # make a new branch
git checkout feature-x    # switch to it

Or do both in one step:

git checkout -b feature-x

More on this in Branches explained.

The one that saves you

git diff

Shows the exact lines you changed before you commit. A quick look here prevents a lot of “oops” commits.

A friendly tip

If you ever feel lost, do not panic and start typing random commands you found online. Run git status first, read what it says, and most of the time it will literally tell you what to do next. Git is scary mainly because nobody reads its messages.

Support this post Sponsor