Every Git project has four key areas:
| Area | Description |
|---|---|
| Working Directory | Where you write and edit code locally |
| Staging Area (Index) | Where you prepare changes before committing |
| Local Repository | Your local commit history (the .git folder) |
| Remote Repository | The central repo hosted on GitHub |
git --version # Check Git is installed
git config --global user.name "Your Name"
git config --global user.email "you@example.com"mkdir git-trained
cd git-trained
git initgit clone https://github.com/Adventuric/git-trainedgit remote add origin https://github.com/Adventuric/git-trainedgit add . # Staging all changes
git add -A # Stage all files and folders
git status # Check what's staged / untracked
git commit -m "your message" # Commit staged changes
git commit -a -m "your message" # Commiting without staging changes
git push <git-trained> main # Push to GitHubWork on features or fixes without touching the main codebase.
git branch <new-branch> # Create a branch
git checkout <new-branch> # Switch to it
# or do both at once:
git checkout -b <new-branch>
git branch # List all branches
git checkout main # Switch back to maingit checkout main
git merge <branch-name>git branch -d <branch-name> # Safe delete (merged only)
git branch -D <branch-name> # Force delete
git push git-trained --delete <branch-name> # Delete from GitHubTemporarily save uncommitted work so you can switch context.
git stash # Save changes, clean working dir
git stash save "label-name" # Stash with a label
git stash list # View all stashes
git stash clear # Delete all stashesgit status # See staged, unstaged, and untracked files
git log # View commit history
git diff # Compare working directory vs staging areagit checkout <commit-hash> file.txtUse
git logto find the commit hash.HEADalways points to your latest commit.
Create a .gitignore file to exclude logs, secrets, and build artifacts:
touch .gitignore
echo "*.log" >> .gitignore # Ignore all .log files
echo "node_modules/" >> .gitignore # Ignore node_modules folder
echo ".env" >> .gitignore # Ignore environment variables filegit rm "filename" # Remove from repo and working directory
git rm --cached "filename" # Remove from staging only (keep local file)git checkout -f # Discard ALL uncommitted changes (use with caution)| Command | What it does |
|---|---|
git init |
Initialize a new local repo |
git clone <url> |
Copy a remote repo locally |
git add . |
Stage all changes |
git commit -m "msg" |
Save a snapshot |
git push origin main |
Upload to GitHub |
git pull origin main |
Download + merge from GitHub |
git branch <name> |
Create a branch |
git checkout <branch> |
Switch branches |
git merge <branch> |
Merge branch into current |
git stash |
Temporarily save uncommitted work |
git log |
View commit history |
git diff |
Compare working dir vs staging |
git status |
Check current repo state |