Here’s a clear, practical guide to Git commands you’ll use in Visual Studio Code (VS Code), with descriptions and when to use them.
git config --global user.name "Your Name"
git config --global user.email "your@email.com"👉 Sets your identity for commits.
git config --list👉 Shows your current Git configuration.
git init👉 Turns your project folder into a Git repository.
git clone <repo-url>👉 Downloads an existing repo (e.g., from GitHub).
git status👉 Shows:
- modified files
- staged files
- untracked files
git add filename👉 Add one file
git add .👉 Add all changes
git commit -m "Your message"👉 Saves staged changes with a message.
git loggit log --oneline👉 Short version of history
git branch branch-namegit checkout branch-nameOR (modern way):
git switch branch-namegit checkout -b branch-namegit branchgit merge branch-name👉 Merge another branch into current branch.
git remote add origin <repo-url>git remote -vgit push origin branch-name👉 First push:
git push -u origin branch-namegit pull origin branch-name👉 Fetch + merge
git fetch👉 Downloads changes without merging.
git reset filenamegit checkout -- filenamegit reset --soft HEAD~1👉 Undo last commit, keep changes
git reset --hard HEAD~1👉
git clean -fgit stashgit stash popInside Visual Studio Code you can:
-
Use Source Control panel (left sidebar)
-
Click + to stage files
-
Type commit messages directly
-
Use built-in buttons for:
- Push / Pull
- Branch switching
- Merge conflict resolution
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <repo-url>
git push -u origin main- Commit often with meaningful messages
- Use branches for features (
feature-login, etc.) - Pull before pushing to avoid conflicts
- Use
.gitignoreto exclude unnecessary files
If you want, I can give you:
- 🧩 Git commands cheat sheet PDF style
- ⚔️ Merge conflict solving guide
- 🚀 Beginner → advanced Git roadmap
You already pushed your code to a different branch, and now you want it in main. Here are the clean ways to fix it:
This keeps history clean and safe.
git checkout maingit pull origin mainReplace
your-branch-namewith your branch name
git merge your-branch-namegit push origin mainIf you don’t care about keeping the branch:
git push origin your-branch-name:main👉 This sends your branch code directly to main.
- Go to GitHub
- Open your repository
- You’ll see a button like “Compare & pull request”
- Click it → Create Pull Request → Merge into
main
- If there are conflicts, Git will ask you to fix them before merging
- Always pull the latest
mainbefore merging - Don’t delete your branch until everything works
Just tell me 👍
