Git Commands
📋 Video Tutorials
Jump to any video:
Untrack Files Locally
When you have files that you modify frequently locally but don't want to commit these changes, you can use Git's assume-unchanged feature.
Untrack files locally
# Untrack a file (Git will ignore local changes)
git update-index --assume-unchanged <filenamewithfullpathfromdotgitfolder>
# Track the file again
git update-index --no-assume-unchanged <filenamewithfullpathfromdotgitfolder>
# Example
git update-index --assume-unchanged datafile.properties
Revert a Wrong Branch Pull
If you've pulled the wrong branch and want to revert it, follow these 4 steps:
Revert wrong branch pull
# Step 1: Check the commit history
git log
# Look for the commit hash of the state you want to revert to
# (usually, this is the one just before the pull)
# Step 2: Reset your branch to the desired commit
git reset --hard <commit_hash>
# Step 3: Clean up any new files introduced by the pull
git clean -f
# Step 4: Verify the status
git status
tip
Always double-check the commit hash before running git reset --hard as this operation cannot be easily undone.
PowerShell Scripts
Delete All Local Branches
Delete all local branches except the main branch using PowerShell:
Delete all branches except main
git branch | Where-Object { $_.Trim() -ne "main" } | ForEach-Object { git branch -D $_.Trim() }
warning
Be careful when deleting branches. Make sure you don't need any of the branches before running this command.
Copy a Repo Fast with Git Archive
Export tracked files as a zip
git archive --format=zip HEAD > project.zip
Why this works:
- Copies only tracked files
- Automatically respects
.gitignore - No build artifacts or dependencies
Works for: Java | TypeScript | Python
Skips automatically: node_modules/, target/, dist/, venv/, __pycache__/
Golden Rule
If Git can regenerate it, don't copy it.
Extract Directly Into a Folder
Extract files without leaving a zip behind.
Linux / macOS / Git Bash (Windows)
# Extract a specific folder from the repo
git archive HEAD tests/AIEvaluation | tar -x
# Extract into a specific location
git archive HEAD tests/AIEvaluation | tar -x -C /path/to/destination