git config --global user.name "FirstName LastName"
git config --global user.email "your-email@exemple.com"
git stash -u
git switch feature/branchName
git stash pop
The pop command reapplies the changes and automatically removes the temporary stash from Git's memory.
git config --list
git config --show-origin --list
Very handy for determining whether a setting is locked at the Local or Global levelgit config --global pull.rebase true
git branch --format='%(refname:short)' | wc -l
git branch --set-upstream-to=origin/branchName branchName
git branch --set-upstream-to=origin/my-remote-branch my-local-branch
The local branch “my-local-branch” will then be configured to track “origin/my-remote-branch”
git switch -c newFeature
git branch -r
git push origin --delete branchName
origin/fix/install-crane-watch-image
origin/feature/autoPR-watch-distroless
origin/feature/improve-staging-add-scan-image
2. Delete a single branch with:
git push origin --delete fix/install-crane-watch-image
Or, delete multiple branches:
git push origin --delete feature/autoPR-watch-distroless \
feature/improve-staging-add-scan-image
3. Local-to-remote synchronization with: git fetch -pgit branch -d branchName
git diff branch1..branch2 --name-only
git clone --depth 1
Shallow cloning is perfect for machines, but has limitations for humans:
Incomplete git log: If you type git log, you will see only a single commit (the latest one)git update-index --chmod=+x ci-script/install-trivy.sh
git ls-files --stage ci-scripts/install-trivy.sh
If the result starts with 100644: The file is not executablegit commit --allow-empty -m "Trigger CI/CD pipeline" && git push
git rev-parse --short HEAD
docker build -t myapp:$(git rev-parse --short HEAD) .git tag -a v1.0.0 -m "Release production"
git switch main
git tag -a v1.0.0 -m “Release production”
-a: Creates an “annotated” tag (recommended). It contains the date, the author's name, and a message. git cherry-pick a1b2c3d4
git rebase -i HEAD~5
git reset --hard abc123
git reset --hard HEAD~1git reset HEAD~1
git reset --soft HEAD~1
The files remain in the “Ready to be committed” (staged) state.
git commit --amend --no-edit
git revert abc123
git filter-repo --mailmap new-author.txt
New Name nouvel.email@example.com Old Name ancien.email@example.comNew Name nouvel.email@example.com ancien.email@example.comgit-filter-repo --path PATH-TO-YOUR-FILE --invert-paths --force
git log --oneline
git log --oneline --graph -10
git log -S "keyword"