Common Operations

Auto-Staging When Committing

Tagging Old Commits

Nth-to-last Commit

Exploring Versions/Commits

Checking Specific Commits

Copy Hash to Clipboard


Basic Commit

Create a commit to save the changes you've made to your repository. This is the fundamental use of the command.

Commit Message

You provide a commit message to describe the changes you've made. A good commit message is clear, concise, and explains the purpose of the changes.

Staging Changes

Before committing, you stage the changes you want to include in the commit using git add. This allows you to selectively choose which changes to include in the commit.

Commit All Changes

Using git commit -a or git commit --all you can commit all changes, including modified and deleted files, in a single command. However, it doesn't commit newly added files.

Amending Commits

You can use git commit --amend to modify the most recent commit. This is useful for fixing mistakes in the commit message or adding changes you forgot to include.

Example

If you have a small amount of changes and you want to include them in the previous commit, you can use the git commit --amend command with the --no-edit flag.

There is a simple procedure:

  1. Stage the Changes with git add
  2. Amend the Previous Commit:
    1. You can commit with no change to previous commit message or with an updated message:
      1. No change to commit message: Use git commit --amend --no-edit where the --no-edit specifying no edit to previous commit message.
      2. Updated commit message: Use git commit --amend -m "<new msg>" to ammend to the previous with an upated commit message.
  3. Push the Changes using git push
    1. Make sure to push using

      git push origin <branch-name> --force