100 useful Git commands - sudo-arshia/tips_and_tricks GitHub Wiki

Command Description Switches/Features
git init Initializes a new Git repository.
git clone <repository> Clones a repository from a URL.
git add <file> Adds a file to the staging area.
git commit -m "<message>" Commits the changes in the staging area.
git status Shows the current status of the repository.
git diff Shows changes between the working directory and the staging area.
git diff <commit> Shows changes between the working directory and a specific commit.
git diff --staged Shows changes between the staging area and the last commit.
git diff <commit1> <commit2> Shows changes between two commits.
git log Displays the commit history.
git log --oneline Displays the commit history in a condensed format.
git log --graph Displays the commit history in a text-based graph.
git branch Lists all branches in the repository.
git branch <branch> Creates a new branch.
git branch -d <branch> Deletes a branch.
git checkout <branch> Switches to a different branch.
git checkout -b <branch> Creates a new branch and switches to it.
git merge <branch> Merges a branch into the current branch.
git remote add <name> <url> Adds a remote repository.
git remote remove <name> Removes a remote repository.
git fetch <remote> Fetches changes from a remote repository.
git pull <remote> <branch> Fetches and merges changes from a remote repository.
git push <remote> <branch> Pushes changes to a remote repository.
git tag <tag> Creates a new tag.
git tag -d <tag> Deletes a tag.
git tag Lists all tags.
git checkout <tag> Checks out a specific tag.
git stash Stashes changes in the working directory.
git stash list Lists all stashes.
git stash apply Applies the latest stash.
git stash drop Removes the latest stash.
git remote rename <old> <new> Renames a remote repository.
git remote set-url <name> <newurl> Changes the URL of a remote repository.
git branch -m <old> <new> Renames a branch.
git branch -a --merged Lists branches merged into the current branch.
git branch -a --no-merged Lists branches not merged into the current branch.
git log --grep="<pattern>" Displays commits with a matching message.
git log -- <file> Displays commits that modified a specific file.
git revert <commit> Reverts changes introduced by a specific commit.
git push <remote> --delete <branch> Deletes a remote branch.
git remote prune <remote> Prunes deleted branches from a remote repository.
git clean Removes untracked files from the working directory.
git bisect start Starts the binary search for a faulty commit.
git bisect good Marks a commit as good during the binary search.
git bisect bad Marks a commit as bad during the binary search.
git bisect reset Ends the binary search and returns to the original branch.
git grep "<pattern>" Searches for a pattern in the repository.
git blame <file> Shows who last modified each line of a file.
git clean -f Removes untracked files without prompting for confirmation.
git diff --name-only <branch1> <branch2> Shows the list of files that differ between two branches.
git stash show -p <stash> Shows the changes made in a specific stash.
git cherry-pick -x <commit> Applies a commit and records its original commit ID.
git stash branch <branch> <stash> Creates a new branch from a specific stash.
git config --global alias.<aliasname> <command> Creates a global Git alias for a command.
git fetch --tags Retrieves remote tags along with the other changes.
git log --no-merges Displays commits excluding merge commits.
git stash clear Removes all stashes.
git remote prune origin --dry-run Shows which remote branches will be pruned.
git stash show -p <stash> Shows the changes made in a specific stash.
git blame -C <file> Shows who last modified each line of a file, even across file renames.
git grep --count "<pattern>" Counts the occurrences of a pattern in the repository.
git clean -f Removes untracked files without prompting for confirmation.
git bisect run <command> Automatically runs a command to determine if a commit is good or bad.
git diff --name-only <branch1> <branch2> Shows the list of files that differ between two branches.
git reflog show <refname> Shows the reflog for a specific reference.
git stash drop -q Removes stashes without displaying any messages.
git merge --no-commit <branch> Merges a branch without creating a new commit.
git push <remote> --tags Pushes all tags to a remote repository.
git cherry-pick -e <commit> Applies a commit and allows editing the commit message.
git stash branch <branch> Creates a new branch from the latest stash.
git config --global --unset alias.<aliasname> Removes a global Git alias.
git fetch --prune origin Prunes deleted branches from the origin remote repository.
git log --follow <file> Displays the commit history for a file, including file renames.
git log --grep="<pattern>" --author=<name> Displays commits with a matching message by a specific author.
git revert --no-edit <commit> Reverts changes without opening an editor for the commit message.
git push <remote> :<branch> Deletes a remote branch.
git remote prune origin Prunes deleted branches from the origin remote repository.
git clean -df Removes untracked files and directories without prompting for confirmation.
git bisect reset <commit> Ends the binary search and moves the branch to a specific commit.
git blame -M <file> Shows who last modified each line of a file, even across file movements.
git grep --name-only "<pattern>" Shows the list of files that contain a pattern.
git bisect reset <commit> Ends the binary search and moves the branch to a specific commit.
git diff --stat <commit1> <commit2> Shows a summary of changes between two commits.
git reflog expire --expire-unreachable=now --all Removes expired reflog entries.
git stash branch <branch> <stash> Creates a new branch from a specific stash.
git config --global --edit Opens the global Git configuration file in an editor.
git branch -vv --all Lists all branches with their corresponding upstream branches.
git cherry-pick --continue --skip Skips a commit during the cherry-pick process.
git stash save --include-untracked Saves changes, including untracked files, in a stash.
git remote set-url --push <name> <newurl> Changes the push URL of a remote repository.
git reset --soft <commit> Moves the branch pointer to a specific commit without modifying the working directory.
git push <remote> --force-with-lease <branch> Forces a push to a remote repository with lease verification.
git bisect visualize --all Opens a graphical visualization of the binary search for all branches.
git reflog delete <refname> Deletes the reflog for a specific reference.
git stash show -u <stash> Shows the changes made in a specific stash, including untracked files.
git cherry-pick --no-commit <commit> Applies a commit without creating a new commit.
git config --global --list Lists all global Git configurations.
git branch -vv --merged Lists branches merged into the current branch, including their upstreams.
git cherry-pick --ff-only <commit> Applies a commit using fast-forward only.
git stash drop -q <stash> Removes a specific stash without displaying any messages.
git stash branch <branch> <stash> Creates a new branch from a specific stash and removes the stash.
git remote rename <old> <new> Renames a remote repository.
git stash show -p <stash> -- <file> Shows the changes made to a specific file in a stash.
git grep --name-only --cached "<pattern>" Shows the list of cached files that contain a pattern.
git bisect run <command> <commit1> <commit2> Automatically runs a command within a specific commit range.
git diff --dirstat <commit1> <commit2> Shows a summary of changes in each directory between two commits.
git reflog delete --expire-unreachable=<date> --all Removes reflog entries that are older than a specific date.
git stash apply -q <stash> Applies a specific stash without displaying any messages.
git config --global --get <key> Retrieves the value of a specific global Git configuration.
git branch -vv --no-merged Lists branches not merged into the current branch, including their upstreams.
git cherry-pick --edit <commit> Applies a commit and allows editing the commit message.
git stash save -p Interactively selects changes to save in a stash.
git remote set-url --add --push <name> <newurl> Adds a new push URL to a remote repository.
git reset --merge <commit> Resets the current branch to a specific commit, preserving changes.
git push <remote> --force-with-lease=<refname>:<expect> Forces a push to a remote repository with lease verification for a specific reference.
git bisect visualize --lines Opens a graphical visualization of the binary search with line-based view.
git stash show -u -p <stash> Shows the changes made in a specific stash, including untracked files, in patch format.
⚠️ **GitHub.com Fallback** ⚠️