Skip to main content
A comprehensive reference for Git commands organized by workflow. Master version control from initial setup through advanced branch management.

Configuration

Set up your Git identity before making any commits.
CommandDescription
git config --global user.name "Nome"Define the global username
git config --global user.email "email"Define the global email address
These settings are stored globally and apply to all repositories on your machine unless overridden locally.

Repository

Commands for initializing and connecting repositories.
CommandDescription
git initInitialize a Git repository in the current folder
git clone <url>Copy a remote repository to your local machine
git remote add origin <url>Link the local repository to a remote repository on GitHub
git init
git remote add origin https://github.com/username/repo.git

Daily Workflow

Essential commands for everyday Git usage.
CommandDescription
git statusShow which files were modified, added, or removed
git add <arquivo>Add a specific file to staging area (prepared for commit)
git add .Add all modified files to staging at once
git commit -m "mensagem"Save a snapshot of staged changes with a descriptive message
git pushSend local commits to the remote repository on GitHub
git push -u origin mainSend and set the default remote branch (required first time)
git pullDownload and integrate changes from remote repository into current branch
git fetchDownload remote changes without integrating them — only updates references
Check status
git status
Stage and commit changes
git add .
git commit -m "Add new feature"
Push to remote
git push
Pull latest changes
git pull

Branches

Work on features in isolation and merge them when ready.
CommandDescription
git branchList all local branches and indicate the current one
git branch <nome>Create a new branch without switching to it
git checkout <nome>Switch to the specified branch
git checkout -b <nome>Create a new branch and switch to it at the same time
git merge <branch>Merge changes from specified branch into current branch
git branch -d <nome>Delete the local branch after it has been merged
Create and switch to new branch
git checkout -b feature/new-feature
Work on feature
git add .
git commit -m "Implement feature"
Merge back to main
git checkout main
git merge feature/new-feature
Delete feature branch
git branch -d feature/new-feature

History and Inspection

Review your project’s commit history and changes.
CommandDescription
git logDisplay complete commit history of current branch
git log --onelineDisplay summarized history, one commit per line
git diffShow differences between modified files and last commit
git log

Undoing Changes

Revert or discard unwanted changes safely.
CommandDescription
git restore <arquivo>Discard changes in a file, reverting to last commit
git restore --staged <arquivo>Remove a file from staging without discarding changes
git revert <hash>Create a new commit undoing changes from a specific commit
git stashTemporarily save uncommitted changes to clean the workspace
Avoid using git reset --hard on shared branches — it rewrites history and can cause conflicts for the team.
Save work in progress
git stash
List stashed changes
git stash list
Apply latest stash
git stash pop
Apply specific stash
git stash apply stash@{0}

Best Practices

Commit Messages

Write clear, descriptive commit messages that explain why changes were made, not just what changed.

Commit Often

Make small, frequent commits rather than large, infrequent ones. Easier to track and revert if needed.

Pull Before Push

Always pull the latest changes before pushing to avoid conflicts and merge issues.

Branch Strategy

Use branches for features, fixes, and experiments. Keep main/master branch stable and deployable.

Build docs developers (and LLMs) love