Skip to content

Latest commit

 

History

History
90 lines (75 loc) · 4.92 KB

CHEATSHEET.md

File metadata and controls

90 lines (75 loc) · 4.92 KB

Git Cheatsheet: Mastering Commonly Used Commands

This cheat sheet serves as a quick reference for mastering the most commonly used Git commands. Covering a wide range of topics, including Git basics, branching and merging, advanced concepts, and professional best practices, these commands are organized by category and include explanations and examples to facilitate comprehension and application.

Common Commands:

  • git clone <repository> - Create a local copy of a remote repository.
  • git init - Initialize a new Git repository in the current directory.
  • git add <file> - Stage a file for commit.
  • git commit -m "<message>" - Commit the staged changes with a message.
  • git push - Push committed changes to a remote repository.
  • git pull - Fetch and merge changes from a remote repository.
  • git branch <branch> - Create a new branch.
  • git checkout <branch> - Switch to a different branch.
  • git merge <branch> - Merge a branch into the current branch.
  • git status - Display the current state of the repository.

Branching and Merging:

  • git branch -d <branch> - Delete a local branch.
  • git push <remote> --delete <branch> - Delete a remote branch.
  • git cherry-pick <commit> - Apply changes from a specific commit to the current branch.
  • git rebase <branch> - Reapply commits from the current branch on top of another branch.
  • git cherry-pick --abort - Abort the cherry-pick operation.
  • git rebase --abort - Abort the rebase operation.

Stashing and Cleaning:

  • git stash - Temporarily save changes that have not been committed.
  • git stash pop - Restore changes saved with git stash and remove the stash.
  • git stash apply - Restore changes saved with git stash, leaving the stash in place.
  • git stash drop - Discard the latest stash.
  • git stash list - Display a list of stashes.
  • git stash clear - Remove all stashes.
  • git stash branch <branch> - Create a new branch and restore changes saved with git stash.
  • git clean <args> - Remove untracked files and directories from the working tree.

History and Diffs:

  • git log - Display a log of commits on the current branch.
  • git diff - Show changes made in uncommitted files.
  • git blame <file> - Show the commit and the name of the person who last modified each line of a file.
  • git show <commit> - Display information about a specific commit.
  • git bisect - Perform a binary search through the commit history to find a specific change.
  • git bisect reset - Exit the binary search.
  • git rev-list - List commit objects in reverse chronological order.
  • git rev-list --all - List all commit objects.
  • git rev-list --branches - List commit objects reachable from any branch.
  • git rev-list --remotes - List commit objects reachable from any remote branch.
  • git rev-list --tags - List commit objects reachable from any tag.
  • git rev-list --stdin - Read commit objects from standard input.
  • git rev-list --quiet - Suppress the default output of git rev-list.

Remote Repositories:

  • git fetch - Download objects and references from a remote repository.
  • git fetch --all - Fetch updates from all remote repositories.
  • git fetch --prune - Prune local branches deleted on the remote.
  • git push - Push committed changes to a remote repository.
  • git push --tags - Push all tags to the remote repository.
  • git ls-remote - Display references in a remote repository.
  • git remote prune <remote> - Remove local branches deleted on the remote.
  • git remote add <remote> <url> - Add a new remote repository.
  • git remote set-url <remote> <url> - Set the URL for a remote repository.
  • git remote rename <old> <new> - Rename a remote repository.
  • git remote show <remote> - Display information about a remote repository.
  • git remote - List remote repositories for the current repository.

Tags:

  • git tag <tag> - Add a tag to the current commit.
  • git tag -d <tag> - Delete a local tag.
  • git push <remote> --delete <tag> - Delete a remote tag.

Miscellaneous:

  • git log --oneline - Display a condensed summary of the commit history.
  • git log --decorate - Display references in the commit log.
  • git log --graph - Display a graphical representation of the commit history.
  • git log --follow <file> - Display the commit history for a file, including renames.
  • git shortlog - Display a summary of commits by author.
  • git describe <ref> - Display a human-readable description of a commit.
  • git reset <file> - Remove a file from the staging area.
  • git mv <old> <new> - Rename a file.
  • git rm <file> - Remove a file from the repository and the filesystem.
  • git show-ref - List references in the local repository.
  • git for-each-ref - Perform an action on each reference.
  • git symbolic-ref <ref> <name> - Create a symbolic reference.
  • git symbolic-ref --short <ref> - Expand a symbolic reference to its shorthand name.
  • git for-each-ref --format <format> - Customize the output of git for-each-ref.