Git_Commands_Guide
Git_Commands_Guide
Configuration Commands
- git config --global user.name "Your Name": Set the global username for commits
- git config --global user.email "[email protected]": Set the global email for commits
- git config --list: View all Git configuration settings
Repository Setup
- git init: Initialize a new Git repository
- git clone <repository_url>: Clone an existing repository
Committing Changes
- git commit -m "Commit message": Commit staged changes
- git commit --amend -m "New message": Modify the last commit message
Undoing Changes
- git revert <commit_hash>: Create a new commit that undoes a specific commit
- git reset --hard <commit_hash>: Move HEAD to an older commit and remove all changes
Stashing Changes
- git stash: Save uncommitted changes
- git stash list: Show all stashed changes
- git stash pop: Apply and remove the most recent stash
Remote Repositories
- git remote -v: List all remote repositories
- git push origin <branch>: Push local changes to remote branch
- git pull origin <branch>: Pull latest changes from a remote branch
Rebasing
- git rebase <branch>: Reapply commits on top of another base branch
- git rebase --abort: Cancel the rebase process
Tagging
- git tag: List all tags
- git tag -a <tag_name> -m "Tag message": Create an annotated tag
Cherry-Picking
- git cherry-pick <commit_hash>: Apply a specific commit from another branch
Submodules
- git submodule add <repository_url>: Add a submodule to the repository
- git submodule update --init --recursive: Initialize and update all submodules
Cleaning Up
- git clean -n: Show files that would be deleted
- git clean -f: Delete untracked files
Advanced Git
- git bisect start: Start a binary search to find a bug
- git blame <file>: Show who changed each line in a file