Configuration
Initial Configuration
Initial Configuration
Set up your Git identity before making any commits.
| Command | Description |
|---|---|
git config --global user.name "Nome" | Define the global username |
git config --global user.email "email" | Define the global email address |
Repository
Commands for initializing and connecting repositories.| Command | Description |
|---|---|
git init | Initialize 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 |
Daily Workflow
Essential commands for everyday Git usage.| Command | Description |
|---|---|
git status | Show 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 push | Send local commits to the remote repository on GitHub |
git push -u origin main | Send and set the default remote branch (required first time) |
git pull | Download and integrate changes from remote repository into current branch |
git fetch | Download remote changes without integrating them — only updates references |
Typical Daily Workflow
Typical Daily Workflow
Check status
Stage and commit changes
Push to remote
Pull latest changes
Branches
Work on features in isolation and merge them when ready.| Command | Description |
|---|---|
git branch | List 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 |
- Feature Branch Workflow
- Quick Branch Switch
Create and switch to new branch
Work on feature
Merge back to main
Delete feature branch
History and Inspection
Review your project’s commit history and changes.| Command | Description |
|---|---|
git log | Display complete commit history of current branch |
git log --oneline | Display summarized history, one commit per line |
git diff | Show differences between modified files and last commit |
Undoing Changes
Revert or discard unwanted changes safely.| Command | Description |
|---|---|
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 stash | Temporarily save uncommitted changes to clean the workspace |
Stash Workflow
Stash Workflow
Save work in progress
List stashed changes
Apply latest stash
Apply specific stash
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.