| Command | Description |
|---|---|
| git config --global user.name $name | Configure user name |
| git config --global user.email $mail | Configure user email |
| Command | Description |
|---|---|
| git init | Create a new repository in the current directory |
| git clone $repository | Download an existing repository from a remote url |
| git remote -v | Show the URL of the remote repository |
| Command | Description |
|---|---|
| git branch | List existing branches |
| git branch $branch-name | Create a new branch |
| git checkout -b $branch-name | Create a new branch and switches to it |
| git push --set upstream $remote-repository $branch-name | Create a local branch remotely |
| git switch $branch-name | Switch to an existing branch |
| git fetch | Retrieve updated branch information from the remote repository without merging them locally |
| git checkout $branch -- $file | Get a file from a branch |
| git ls-files | Show the tracked files |
| git merge | Combine the history of another branch into the current branch |
| git merge --abort | Aborts the current merge operation |
| git branch [-d|-D] $branch-name | Delete a local branch.-d deletes the branch if it has already fully merged.-D deletes the branch regardless of its merged status |
| git push $origin --delete $branch-name | Delete a remote branch |
| git rebase | Reapplies commits from a branch on top of another branch (potentially rewriting history) |
| Command | Description |
|---|---|
| git add (.|file) | Add files to the staging area for the next commit |
| git rm [-rf] --cached ($file|$directory) | Delete a file/directory from the staged area |
| git commit -ma $message | Crete a new commit with a message |
| git commit --amend -m $message | Correct the message from the last commit |
| git pull | Fetch updates from the remote repository and attempts to merge them into the current local branch |
| git push [--follow-tags] | Upload local commits to the remote repository |
| git blame | Show who last modified each line of a file |
| git cherry pick | Selectively applies a commit from another branch to the current branch |
| Command | Description |
|---|---|
| git tag [-a|-d] $tag | Create/delete a local tag for a specific commit |
| git tag -l [$regex] | List tags |
| git show-ref --tags | Show commits for all tags |
| git rev-list -n1 $tag | Show which commit has a certain tag |
| git push --delete origin $tag && git tag -d $tag | Delte a remote tag and, then, delete the local tag |
| Command | Description |
|---|---|
| git checkout [file] | Discard uncommited changes to the file |
| git reset [--hard] [file|commit] | Move the HEAD pointer to a specific commit (hard removes local changes since then) |
| git reset --soft HEAD-1 | Undo the last commit |
| git revert | Create a new commit that undoes the changes introduced by another commit |