Skip to content

Frequently used Git commands (FREE ALL)

The following commands are frequently used.

Add another URL to a remote

Add another URL to a remote, so both remotes get updated on each push:

git remote set-url --add <remote_name> <remote_url>

Refs and Log

Use reflog to show the log of reference changes to HEAD

git reflog

Check the Git history of a file

The basic command to check the Git history of a file:

git log <file>

If you get this error message:

fatal: ambiguous argument <file_name>: unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:

Use this to check the Git history of the file:

git log -- <file>

Check the content of each change to a file

gitk <file>

Check the content of each change to a file, follows it past file renames

gitk --follow <file>

Rebasing

Rebase your branch onto the default

The -i flag stands for 'interactive'. Replace <default-branch> with the name of your default branch:

git rebase -i <default-branch>

Continue the rebase if paused

git rebase --continue

Use git rerere

To reuse recorded solutions to the same problems when repeated:

git rerere

To enable rerere functionality:

git config --global rerere.enabled true