The only Git guide you need for 95% of your daily development workflow. Save this post or bookmark it — it’s your quick-fix toolkit for everyday Git challenges.
Why This Guide
Git can feel complicated when you are managing multiple branches, commits, and conflicts. Whether you are a developer, team lead, or project manager, this post walks through real-world Git scenarios and commands that actually work, not just theory.
Starting with a Project
Example: You just joined a new project
Your teammate shares a GitHub repository link.
git clone https://github.com/team/project.git
cd project
This downloads the full project and takes you into the project folder.
Example: Switching to the branch you are assigned to
You were told to work on the feature/login branch.
git switch feature/login
The switch command is a modern and simpler alternative to checkout.
Example: Get the latest updates from your team
Always pull the latest code before starting work for the day.
git pull
This fetches and merges new changes from the remote repository.
Working with Code
Example: Check what you have changed so far
Before committing, check your modifications.
git status
This shows modified and untracked files. Use it frequently to stay aware of your workspace state.
Example: Save your work with a clear message
git add .
git commit -m "Added login form validation"
Write meaningful commit messages so that your team can understand the context later.
Example: Push your work to GitHub
git push
Your local commits are now uploaded to the remote repository.
Example: Commit only specific files
If you fixed a bug in auth.js but do not want to include other changes:
git add auth.js
git commit -m "Fix token validation logic"
This keeps commits clean and focused.
Example: Unstage a file added by mistake
git restore --staged package-lock.json
This removes the file from staging without deleting it.
Working with Branches
Example: Create a new feature branch
You are starting a new feature called user dashboard.
git switch -c feature/user-dashboard
This creates and switches to the new branch.
Example: Delete a branch you no longer need
After merging feature/user-dashboard:
git branch -d feature/user-dashboard
If Git prevents deletion because it is not merged:
git branch -D feature/user-dashboard
To delete the branch from the remote repository:
git push origin --delete feature/user-dashboard
Example: Rename your branch
git branch -m feature/dashboard-ui
git push origin -u feature/dashboard-ui
git push origin --delete old-branch-name
Fixing Your Mistakes
Example: Revert files back to the last commit
git restore .
To revert a single file:
git restore app.js
Example: Forgot to add a file in your last commit
git add config.js
git commit --amend --no-edit
This updates the last commit without changing its message.
Example: Change your last commit message
git commit --amend -m "Fix: update production configuration"
Example: Undo the last commit but keep your changes
git reset --soft HEAD~1
Your changes remain in your working directory.
Example: Undo the last commit and discard changes
git reset --hard HEAD~1
Be careful — this permanently removes your changes.
Example: Fix a commit already pushed
You can still amend it if it is your own branch.
git commit --amend
git push --force
Avoid using force push on shared branches.
Working with Others
Example: Pull teammates’ changes
git pull
This brings new updates from the remote branch.
Example: Pull not working due to local changes
Temporarily save your work before pulling.
git stash
git pull
git stash pop
Your local changes are safely reapplied after pulling.
Example: Resolve merge conflicts
Open the files with conflicts.
Look for the markers:
<<<<<<< HEAD
your code
=======
their code
>>>>>>> branch-nameChoose the code to keep and delete the markers.
Save the file and run:
git add .
git merge --continue
To cancel the merge:
git merge --abort
Example: Update your branch with the main branch
git switch main
git pull
git switch feature/login
git merge main
Fix conflicts, then run:
git add .
git merge --continue
git push
Some Advanced Techniques
Example: Combine multiple small commits into one
You made several small commits that can be combined.
git reset --soft HEAD~3
git commit -m "Fix login validation issues"
git push --force
This results in a single, clean commit.
Example: Copy a specific commit from another branch
git log
git cherry-pick a1b2c3d
This brings the specified commit into your branch.
Example: Rebase to update your branch cleanly
git pull --rebase
This avoids unnecessary merge commits and keeps history linear.
If conflicts occur:
git add <files>
git rebase --continue
To cancel the rebase:
git rebase --abort
Emergency Help
Example: Revert a bad commit that was already pushed
git revert <commit-code>
git push
This safely undoes the commit by creating a new one.
Example: Make your branch identical to another branch
git reset --hard origin/main
This resets your branch completely to match the remote main branch. Be cautious, as this deletes all local changes.
Example: Recover deleted commits
git reflog
Find the commit and restore it:
git cherry-pick <commit-code>
Quick Reference
# Check current changes
git status
# Save and push work
git add .
git commit -m "message"
git push
# Pull latest updates
git pull
# Create and switch branches
git switch -c <branch>
git switch <branch>
# Undo changes
git restore .
# Temporarily save and restore work
git stash
git stash pop
Common Problems and Fixes
Problem: Your branch has diverged
git pull --rebase
Problem: Merge conflict Fix conflicts manually, then run:
git add <file>
git merge --continue
Problem: Permission denied Check your SSH credentials or repository access.
Problem: Forgot to commit before switching branches
git stash
git switch <branch>
git stash pop
Final Tip
When unsure, always run:
git status
It will tell you exactly what Git expects next and help you stay in control of your workflow.
Conclusion
Git does not have to be difficult. By practicing these commands daily and understanding what each one does, you can handle almost every common Git issue confidently and efficiently. Keep this guide handy and share it with your teammates whenever Git issues arise.

