Version control with Git is crucial for managing your codebase efficiently. This article covers important Git commands used in production and local environments with practical examples.
Remote repo : origin/feature/2025
Local repo : feature/2025
git log origin/feature/2025..feature/2025 --oneline
π Explanation: Shows commits that exist locally but not in the remote branch.
βοΈ Example Output:
8e3c1db Updated home page styles
d2a4f32 Added new API endpoint for views
git log feature/2025..origin/feature/2025 --oneline
π Explanation: Shows commits that exist in the remote but not locally.
βοΈ Example Output:
f6d7aab Bug fix in auth middleware
c8e9b23 Updated README with deployment steps
git log --oneline --graph --decorate --abbrev-commit origin/feature/2025..feature/2025
π Explanation: Visualizes commits only in your local branch compared to remote with a graph view.
βοΈ Example Output:
* d2a4f32 (HEAD -> feature/2025) Added new API endpoint for views
* 8e3c1db Updated home page styles
git diff origin/feature/2025..feature/2025
π Explanation: Shows file changes in local that are not in remote.
git diff feature/2025..origin/feature/2025
π Explanation: Shows file changes in remote that are not in local.
git fetch
π Explanation: Downloads updates from remote branches without merging them into your local branch.
sudo git pull --no-rebase
Merges remote changes into local branch, creating a merge commit if necessary.
sudo git pull --rebase
Reapplies your local commits on top of remote commits for a linear history.
sudo git pull --ff-only
Updates your branch only if it can be fast-forwarded; otherwise, it aborts.
git config pull.rebase true # Always rebase on pull
git config pull.rebase false # Always merge on pull
sudo git rm --cached mysite/db.sqlite3
echo "/mysite/db.sqlite3" >> .gitignore
sudo git add .gitignore
sudo git commit -m "Stop tracking db.sqlite3 and update .gitignore"
sudo git push
βοΈ Explanation:
git rm --cached untracks the file while keeping it locally.
Adds it to .gitignore to prevent future tracking
These Git commands help you:
Manage divergent branches
Check commit differences
Pull and merge efficiently
Avoid database merge conflicts in production
Maintain clean Git practices
Keep this as your Git command cheat sheet for daily development, deployments, and server management.