Git
SSH Keys
GitHub Docs (Windows/Linux/Mac)
After setting up your SSH key on your machine, set your name and email in the local git config:
git config --global user.name "full name"
git config --global user.email "email"Frequent Commands
git fetch
git pull
git add .
git status
git commit -m "Descriptive message"
git pushUndoing
The Holy Grail
git reset --hard HEAD^ git push origin -f
Reverting staged changes:
git reset
git reset path/to/fileReverting commits:
git log # View commit history
git revert HEAD # Previous commit
git revert <commit_id> # Targeted commitBranching
Branching off the current branch:
git branch <branch_name>Switching to an existing branch:
git checkout -b <target_branch>Create and switch to the new branch:
git checkout -b <branch_name>Deleting a branch locally:
git branch -d <target_branch>Deleting a branch remotely:
git push origin --delete <target_branch>Renaming a branch:
git branch -m <old_name> <new_name>Merging
Merging a branch back into the main branch:
git checkout main
git merge <target_branch>Merging a branch into target branch:
git checkout <target_branch>
git merge <source_branch>
git push -u origin <target_branch>Cancelling a merge:
git merge --abortClearing the Cache
git rm --cached