Back Jul 20, 2024 · 6 min read
Git Command Datasheet
Quick reference for the most-used Git commands: setup, branches, commits, syncing and undoing changes.
GitCLIReferencia
Quick reference for the most-used Git commands day to day: setup, branches, commits, syncing with the remote, and undoing changes.
01 · Configuration
| Command | Description |
| git config --global user.name "Your Name" | Sets your username. |
| git config --global user.email "youremail@example.com" | Sets your email address. |
02 · Initialization
| Command | Description |
| git init | Initializes a new repository. |
| git clone REPOSITORY-URL | Clones an existing repository. |
03 · Repository status
| Command | Description |
| git status | Shows the repository's status. |
04 · Tracking changes
| Command | Description |
| git add file-name | Adds a specific file to the staging area. |
| git add . | Adds all changes to the staging area. |
| git reset file-name | Removes a file from the staging area. |
05 · Branches
| Command | Description |
| git branch -a | Lists all branches. |
| git branch -m branch-name | Creates or renames a branch. |
| git branch -d branch-name | Deletes a branch. |
| git checkout branch-name | Switches to an existing branch. |
| git checkout -b new-branch-name | Creates and switches to a new branch. |
| git diff branch1 branch2 | Compares two branches. |
06 · Change history
| Command | Description |
| git log | Shows all commits with their IDs. |
| git checkout commit-id | Switches to a specific commit. |
| git diff commit-id-1 commit-id-2 | Compares two commits. |
07 · Commits
| Command | Description |
| git commit -m "your message" | Records changes with a message. |
| git push | Pushes changes to the remote repo (current branch). |
| git push origin branch-name | Pushes changes to a specific remote branch. |
08 · Syncing
| Command | Description |
| git pull | Fetches and merges changes from the remote. |
| git fetch | Shows differences between local and remote. |
09 · Undoing changes
| Command | Description |
| git checkout -- file-name | Discards changes in a modified file. |
| git reset --soft HEAD~1 | Undoes a commit, keeping the changes. |
| git reset --hard HEAD~1 | Undoes a commit and discards the changes. (Caution) |
10 · Other actions
| Command | Description |
| git diff | Shows uncommitted changes. |
| git log file-name | Shows the history of a specific file. |
| git tag tag-name | Tags a commit. |
Additional notes
Caution: some commands can cause data loss, such as git reset --hard.
Help: use git help command-name for more information about each command.