a comprehensive Git cheat sheet with many of the commonly used Git commands in table format:
commands in table format:
Command | Description |
---|---|
git init | Initialize a new Git repository in the current directory |
git clone <url> | Clone an existing Git repository located at <url> to your local machine |
git add <filename> | Add a file or changes to a file to the staging area |
git add . | Add all changed files to the staging area |
git commit -m "<message>" | Commit changes to the repository with a message describing the changes |
git commit -a | Add all changed files and commit with a message |
git status | Show the status of the current working directory |
git diff | Show the differences between the working directory and the staging area |
git diff --cached | Show the differences between the staging area and the last commit |
git log | Show the commit history for the repository |
git log --oneline | Show the commit history in a condensed format |
git log --graph | Show the commit history as a graph |
git branch | List all local branches in the repository |
git branch <branchname> | Create a new branch with the specified name |
git branch -d <branchname> | Delete the branch with the specified name |
git checkout <branchname> | Switch to the specified branch |
git checkout -b <branchname> | Create and switch to a new branch with the specified name |
git merge <branchname> | Merge changes from the specified branch into the current branch |
git remote | List all remote repositories |
git remote add <name> <url> | Add a new remote repository with the specified name and URL |
git push <remotename> <localbranch>:<remotebranch> | Push committed changes from the specified local branch to the specified remote branch |
git pull <remotename> <remotebranch> | Pull changes from the specified remote branch to the current local branch |
git stash | Stash changes in the working directory for later use |
git stash list | List all stashes |
git stash apply | Apply the most recent stash |
git stash apply <stashname> | Apply the stash with the specified name |
git stash drop | Discard the most recent stash |
git stash drop <stashname> | Discard the stash with the specified name |
git tag | List all tags in the repository |
git tag <tagname> | Create a new tag with the specified name at the current commit |
git tag -a <tagname> -m "<message>" | Create a new annotated tag with the specified name and message at the current commit |
git tag -d <tagname> | Delete the tag with the specified name |
git show <commit> | Show information about the specified commit |
git reset <commit> | Reset the repository to the specified commit |
git reset --hard <commit> | Reset the repository to the specified commit and discard all changes |
git clean -f | Remove all untracked files from the working directory |
git clean -f <directory> | Remove all untracked files from the specified directory |