Set your identifying information across all local repositories so your commits are properly attributed 1:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Initialize an existing directory as a new Git repository:
git init
Clone a repository from a GitHub link:
git clone [url]
Prepare your files for the next commit by "staging" them in the index 2:
git add [file]
Unstage a file while keeping the changes in your working directory:
git reset [file]
Check the current status of your working tree and staging area:
git status
Commit your staged content as a new snapshot with a descriptive comment:
git commit -m "[descriptive comment]"
Create a new local branch to start a fresh feature without affecting the main line 3:
git branch [branch-name]
Switch your working directory to a specific branch:
git checkout [branch-name]
Sometimes you need to switch branches but aren't ready to commit. Stashing allows you to "pause" your progress safely.
Save all current changes into a temporary storage area:
git stash
Re-apply your stashed changes to the current branch:
git stash pop
Create a new commit that undoes the changes of a previous one:
git revert [SHA]
While reset is great for fixing local staging errors, revert is the safe way to fix mistakes on shared remote branches because it doesn't "rewrite" the existing history.
Apply the changes from a specific commit on another branch to your current one:
git cherry-pick [SHA]
Fetch all branches from the remote repository:
git fetch [alias]
Push local branch commits to the remote repository branch:
git push [alias] [branch]
Fetch and merge any remote commits from the tracking branch:
git pull
Merge a remote branch into your current local branch:
git merge [alias]/[branch]