Additional Git Commands

Once you’re comfortable with the basics like clone, add, commit, and push, there are a few other commands that can help you manage and understand your repository more.


git status

This is one of the most useful Git commands, especially when you’re not sure what you’ve done recently.

To run this command, use:

$ git status

This will tell you what branch you’re on, which files have been changed, which files are staged or unstaged, and if there are untracked files. Use this to keep track of your workflow and avoid mistakes.

An example of output you may see from git status would be:

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)        
  (use "git restore <file>..." to discard changes in working directory)
        modified:   docs/basics/clone.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)       
        docs/advanced/ssh.md

no changes added to commit (use "git add" and/or "git commit -a") 

git remote

This command shows the remote repositories that your local project is connected to. Run it using the following:

$ git remote -v

Your output will typically look something like this:

origin  https://github.com:yourname/your-repo.git (fetch)
origin  https://github.com:yourname/your-repo.git (push)

git log

This shows a history of all commits in your current branch. Type the following:

$ git log

The log view will appear. To quit, press q. The default command with show commit hashes (SHAs), authors, dates, and commit messages for the commits.

For the simplified version, use:

$ git log --oneline

This may give output similar to the following:

1a23bc4 Commit message 1
9z87yx6 Commit message 2

git diff

This shows the differences between your working files and what’s staged or committed. Run using:

$ git diff

Use it to review your changes before committing. If you’ve already staged changes, use:

$ git diff --staged

More commands

Git has many more commands, and each of these (including the ones in this guide) have many additional arguments that can be added on for a more fine-tuned execution.

This guide will not cover all of these in detail - we recommend checking out the official documentation for specific cases!

The documentation for Git assumes prior knowledge and may be confusing for beginners. Don’t worry if this material is difficult to understand at first!


← Merge Conflicts ↑ To Intermediate Git Files →