Git Commands Reference

Clean, task-based cheat sheet for setting up local repos, syncing with GitHub, and using the GitHub CLI.

Clone repository

git clone https://github.com/USER/REPO.git
Purpose
Download a remote repository into a new local folder
When to use
When you want a fresh local copy of an existing repo
Risk notes
Fails if the destination folder already exists and is not empty
git clone https://github.com/USER/REPO.git my-local-folder
Purpose
Clone a repository into a specific local folder name
When to use
When you don’t want the folder name to default to the repo name
Risk notes
If the folder exists, cloning may fail or create nested content depending on your path

Local repo setup

git init
Purpose
Initialize a new local Git repository
When to use
First step in an empty folder
Risk notes
None

Branch naming

git branch -M main
Purpose
Rename current branch to main
When to use
After init, before first push
Risk notes
Renames locally
git branch -M produccion
Purpose
Rename current branch to produccion
When to use
After init, before first push
Risk notes
Renames locally

Create first file

touch README.md
Purpose
Create an initial file to commit
When to use
When folder has no files
Risk notes
None

Stage files

git add .
Purpose
Stage all changes in the folder
When to use
Before committing
Risk notes
Can stage unwanted files

Commit

git commit -m "Initial commit"
Purpose
Create a commit from staged files
When to use
After staging
Risk notes
None

Status check

git status
Purpose
Show staged, unstaged, untracked changes
When to use
Anytime
Risk notes
None

Remote check

git remote -v
Purpose
List configured remotes and URLs
When to use
Before adding or changing remotes
Risk notes
None

Remote setup

git remote add origin https://github.com/USER/REPO.git
Purpose
Add GitHub remote named origin
When to use
After repo exists on GitHub
Risk notes
Fails if origin already exists

Push first time

git push -u origin main
Purpose
Push main and set upstream
When to use
First publish of main
Risk notes
None
git push -u origin produccion
Purpose
Push produccion and set upstream
When to use
First publish of produccion
Risk notes
None

Force push

git push --force origin main
Purpose
Overwrite remote main with local main
When to use
Only when intentionally replacing remote history
Risk notes
Destructive if remote has commits

Pull with rebase

git pull --rebase origin main
Purpose
Update local branch by rebasing on remote
When to use
When remote already has commits
Risk notes
Rewrites local commits during rebase