Expert Git Commands

git add --edit

Interactive staging of changes

git add --patch

Interactively select hunks of changes to stage for the next commit.

git add -i

Interactively add files to the git index

git blame -C

Display author's modifications per line in a file while copying or moving across files

git blame -L <start,end> <filepath>

Displays the author and revision details for specific lines in a file.

git blame -w

Displays who last modified each line of a file, ignoring whitespace.

git checkout --orphan <branchname>

Create a new orphan branch

git checkout -b <branchname> <commit>

Creates and switches to a new branch from a specific commit

git checkout -t <remote>/<branchname>

Create and switch to a new branch tracking a remote branch

git cherry-pick -n <commitA>

Apply the changes in `<commitA>` without making a new commit.

git commit --no-verify

Commit changes without running pre-commit hooks

git config --global --list

List the global configuration settings for Git

git config --global pager.branch false

Disables the use of a pager for the output of the `git branch` command globally.

git config --global push.default current

Set default tracking for new branches

git config --global user.name <username> --replace-all

Sets the global username for git, replacing any existing username

git config --local --list

Show the local configuration settings for Git repository

git diff <commitA> --name-status

Show the file names and status changes between commitA and the current branch

git fetch --prune

Fetches new branches and removes deleted branches

git log --pretty=format:<format_string>

View the commit history in a custom format

git log --show-signature

Displays the git log with GPG signatures.

git log -p

Show the commit log with its diff

git log <commitA>..<commitB>

Show commit logs between commitA and commitB

git merge --no-ff <branchname>

Merge branch without fast-forwarding

git merge-base <branchname1> <branchname2>

Finds common ancestor(s) between two branches

git push --tags

Pushes tags to the remote repository

git remote set-head origin --auto

Automatically sets the default branch of a remote repository

git reset --mixed HEAD~1

Undo last commit, keep changes staged

git rev-list --all -- <pathname>

Lists commit hashes containing changes to a file.

git rev-list --all --objects

Lists all objects in all commits.

git revert HEAD

Reverts the most recent commit

git stash --keep-index

Stashes changes, keeping index intact

git stash apply

Apply the most recent stash to the working directory

git stash push -p -m <message>

Stash changes interactively with a custom commit message

git tag -a <version_number> -m <message>

Create an annotated tag with a specific version number and message

Navigate with the arrow keys or swipe on mobile