Identity Configuration
Initialize or update contributor credentials for a repository. Applying the --global flag extends these settings across all local projects.
git config --global user.name "LeadDeveloper"
git config --global user.email "dev.lead@company.org"
When corrections are required, overwrite existing entries using the replace flag:
git config --global --replace-all user.name "NewAuthor"
git config --global --replace-all user.email "updated.contact@company.org"
Generating Patch Files
Export commit changes into portable patch files. This is particularly useful for offline code reviews or applying changes to alternative repositories.
git format-patch --root
# Target a specific commit hash
git format-patch <commit_sha> -1
Isolating Merge Conflicts
During branch integration, quickly filter and list files that require manual resolution by checking for unmerged states:
git diff --name-only --diff-filter=U
Remote Endpoint Management
Inspect existing upstream connections or switch the repository URL to a different hosting platform:
git remote get-url origin
git remote set-url origin git@gitlab.example.com:team/backend-service.git
Synchronize local work with the remote branch using the currently active branch name:
git pull origin $(git branch --show-current)
Pushing to a code review system requires targeting a specific rfeerence. Submit changes to a review queue while assigning specific reviewers:
git push origin HEAD:refs/for/main
git push origin HEAD:refs/for/main%r=reviewer.one@org.com,reviewer.two@org.com
Tag Lifecycle Operations
Manage version markers through listing, creation, removal, and publication workflows:
git tag --list
git tag -d legacy-v1
git tag -a stable-v2.0 -m "Production release candidate" <commit_sha>
git push origin stable-v2.0
Branch Replay and Rewriting
To integrate upstream modifications while preserving a linear history, switch to your feature branch and replay local commits atop the target branch. This operation rewrites the commit chain to sit directly above the latest upstream state:
git checkout feature-branch
git rebase main
Workspace Cleanup and State Reset
Purge untracked files, directories, and ignored artifacts to return the working directory to a pristine condition:
git clean -fdx
Discard all local modifications and forcefully move the HEAD pointer to a designated historical point:
git reset --hard <target_commit_sha>
Stashing Temporary Changes
Shelve uncommitted work to switch contexts without creating intermediate snapshots:
git stash push -m "experimental-UI-changes"
git stash list
git stash apply stash@{0}
History Recovery via Reflog
Git maintains a local reference log of all HEAD movements. Even after destructive operations like hard resets, browse this log to locate lost commit hashes and restore previous states:
git reflog