- Git Configuration Commands These set up your identity, preferences, and defaults.
Command Description git config --global user.name "Your Name" Sets your Git username (used for commits). git config --global user.email "you@example.com" Sets your email for commits. git config --global core.editor "code --wait" Sets default text editor (e.g., VS Code). git config --list Shows all Git configuration settings.
- Starting a Repository Create or clone a repo.
Command Description git init Initializes a new Git repo in current folder. git clone Clones an existing remote repo from GitHub. git clone Clones repo into a specific folder.
- Staging and Committing Changes Control what changes go into Git history.
Command Description git status Shows changed files and their state. git add Stages a specific file. git add . Stages all changes in the directory. git commit -m "message" Commits staged changes with a message. git commit -am "message" Adds & commits only tracked files in one step.
- Viewing History and Changes Track what happened in the repo.
Command Description git log Shows commit history. git log --oneline Shows compact commit history. git diff Shows unstaged changes. git diff --staged Shows staged changes. git show Shows details of a commit.
- Branching Work on different features or fixes.
Command Description git branch Lists all branches. git branch Creates a new branch. git checkout Switches to a branch. git checkout -b Creates & switches to a branch. git branch -d Deletes a branch. git branch -D Force deletes a branch.
- Merging & Rebasing Integrating work from different branches.
Command Description git merge Merges a branch into the current branch. git rebase Re-applies commits from your branch on top of another. git merge --abort Cancels a merge in progress. git rebase --abort Cancels a rebase in progress. git rebase --continue Continues a paused rebase after resolving conflicts.
- Remote Repositories Connecting to GitHub.
Command Description git remote -v Shows remote repos linked to local repo. git remote add origin Adds a remote named origin. git remote remove Removes a remote. git push -u origin Pushes branch to GitHub and sets tracking. git fetch Gets latest changes without merging. git pull Fetches and merges from remote. git push Pushes local commits to remote.
- Undoing Changes Fixing mistakes.
Command Description git restore Restores file to last committed version. git restore --staged Unstages a file. git reset Moves branch pointer to a commit (keeps changes). git reset --hard Resets to a commit and deletes all changes. git revert Creates a new commit that undoes a commit.
- Tags Marking important commits.
Command Description git tag Lists tags. git tag Creates a tag. git tag -a -m "message" Creates annotated tag with message. git push origin Pushes a tag to remote. git push origin --tags Pushes all tags.
- GitHub-Specific Commands Integration & GitHub CLI.
Command Description gh auth login Logs into GitHub CLI. gh repo create Creates a new GitHub repo. gh repo clone Clones a repo from GitHub. gh issue list Lists GitHub issues. gh pr create Creates a pull request. gh pr merge Merges a pull request.
- Miscellaneous Extra useful commands.
Command Description git stash Temporarily saves uncommitted changes. git stash pop Restores stashed changes. git clean -fd Deletes untracked files/folders. git reflog Shows all branch history (including deleted commits).