This README provides essential Git commands for working with GitHub using Git CMD (Command Prompt), along with brief explanations.
Sets your global Git username (used for all repositories).
git config --global user.name "Your Name"
Sets your global email.
git config --global user.email "[email protected]"
Check local or global Git username.
git config user.name
git config --global user.name
List all config values (local or global).
git config --list
git config --global --list
git init
Initialize a new Git repository.
git clone https://github.com/username/repo.git
Clone an existing repository from GitHub.
git status
Check the status of your working directory and staging area.
git add filename
git add .
Stage file(s) or all files for commit.
git commit -m "Your commit message"
Commit staged changes.
git push origin branch_name
Push commits to GitHub on specified branch.
git pull origin branch_name
Pull latest changes from GitHub.
git branch
List local branches.
git branch new_branch
Create a new branch.
git checkout new_branch
Switch to a branch.
git checkout -b new_branch
Create and switch to a new branch.
git merge branch_name
Merge specified branch into current branch.
git restore filename
Discard changes in working directory (Git 2.23+).
git reset HEAD filename
Unstage a file.
git reset --hard
Reset all files to last commit (warning: destructive).
git rm filename
Delete a file and stage the removal.
git mv oldname newname
Rename a file and stage the rename.
git log
Show commit history.
git log --oneline --graph --all
Compact graph of all commits.
git push https://[email protected]/username/repo.git
Push with username (use PAT/token in place of password).
git config --global user.name "New Name"
git config --global user.email "[email protected]"
Update global Git identity.
git stash
Temporarily save changes without committing.
git stash pop
Apply stashed changes.
git remote -v
Show remote URLs.
git fetch
Download changes without merging.
git diff
See unstaged changes.
git show commit_id
Show details of a specific commit.
Tip: Use SSH or Personal Access Tokens (PAT) for GitHub authentication to avoid password issues.