Advanced Git Commands

git --no-pager diff

Displays `git diff` output without pagination.

git bisect start

Start a binary search for a specific commit.

git branch -a --contains <commit>

List all branches that contain commit <commit>, including remote branches.

git checkout --ours <pathname>

During a merge request choose the version of a file that existed in the current branch

git checkout --theirs <pathname>

Resolve a merge conflict by accepting the "incoming" branch changes

git checkout -m <branchname>

Switch to a different branch and merge changes

git cherry-pick <commitA>^..<commitB>

Cherry-pick several commits

git clean -fd

Remove untracked files and directories from your git repository

git config --global user.name <username>

Set the global username for git

git diff @{upstream}

Show differences between local branch and upstream branch

git gc

Clean up unnecessary files and optimize the local repository

git grep -i "search pattern"

Search for patterns in the repository, ignoring the case of the search pattern

git log --author=<author>

List all commits from a given author

git log --since=<date_or_time>

Show commits since a specific date/time.

git ls-files

Lists all the files tracked by git

git merge <branchname1> <branchname2>

Merge a branch into a target branch

git mv -f <oldfilepath> <newfilepath>

Rename or move a file even if destination (i.e. <newfilepath>) exists

git pull --ff-only upstream <branchname>

Fast-forward merge from `upstream` into current branch.

git pull --rebase

Rebase the remote branch into the local one

git push -u <remote> <branchname>

Push commits to a remote repository

git rebase -i --autosquash HEAD~n

Interactively rebase with autosquash for last n commits.

git rebase -i HEAD~<number>

Interactively rebase the last <number> commits.

git rebase <branchname> -i

Interactively rebase current branch onto `<branchname>`.

git remote prune origin

Remove stale remote-tracking branches.

git remote set-url origin <url>

Changes the url of the `origin` remote repository.

git reset --hard

Discard all changes and revert to the commit specified

git reset --soft HEAD~1

Reset the current branch and move the HEAD pointer to the previous commit, keeping the changes staged.

git reset <commit> --merge

Undo commits without touching the working tree.

git rev-parse --symbolic-full-name --abbrev-ref HEAD

Obtain the name of the current branch

git show --name-status <commit>

Displays the names and status of files modified in a specific commit.

git stash -k

Stashes changes in the working directory, but keeps the untracked files

git stash -u

Stash all changes including untracked files

git stash apply stash@{<number>}

Apply a specific stash to the working directory

git stash clear

Remove all stashed entries

git stash show -p

Shows the content of the last stash

git tag <version_number>

Create a new tag with the specified version number

Navigate with the arrow keys or swipe on mobile