DEV Community

Nagesh K
Nagesh K

Posted on

Git -> Quick Drill Sheet

Important concepts you understood:
Working Directory 👉 Where you edit files
Staging Area 👉 Temporary place before commit
Commit 👉 Snapshot of project
Local Repository 👉 Git history on your machine
Remote Repository 👉 GitHub copy of your project

Git Workflow (Most Important) : Always remember this pipeline.
Working Directory
↓
git add
↓
Staging Area
↓
git commit
↓
Local Repository
↓
git push
↓
GitHub

Faster shortcut (useful for single file edits)
git commit -am "updating git_notes.txt"
Reason: -a automatically stages modified files (not new files).

Topic Key Command
Repository files ls
Create files echo "text" > file
Read file cat file
Check repo status / See modified, staged, and branch info git status
Staging area git add file / git add .
Undo staging git reset file
add remote origin git remote add origin <repo-URL>
Commit changes git commit -m "message"
Push to GitHub git push -u origin main
Pull from GitHub git pull origin main
Merge repos with different histories git pull origin main --allow-unrelated-histories
View commit history git log
Short commit history git log --oneline
File-specific history git log -- filename
Repository connection git remote -v
Cloning a repo git clone <repo-URL>
Branch info git branch
Delete empty files find . -type f -empty -delete
Delete files in Git git rm file + git commit
create + switch branch git checkout -b <branch name>
Switch branches(new way) git switch branchname and git switch -c newbranch
Branch info git branch => * feature1 , main
delete Branch git branch -d <name>

Core workflow you practiced
Edit file
↓
git add .
↓
git commit -m "message"
↓
git push

Branching Strategy :-

git checkout -b newfeature | new branch from main branch
edit files | edit the files
git add README.md | staging
git commit -m "update" | commit changes
git push origin newfeature | push updates in new branch

------ CODE REVIEW HAPPENS HERE ------
Pull Request → reviewers check code → CI tests run → approval

git checkout main | switch to main branch
git merge newfeature | merge the newfeature to main branch
git push origin main | to get updated content
git branch -d newfeature | delete the feature branch

Top comments (0)