Here is a simple cheat sheet for some of the most common Git and GitHub commands you can use in your terminal:
- Initialize repository:
git init - Check status of working directory:
git status - Add files to staging area:
git add <file>orgit add .(to stage all changes) - Commit changes:
git commit -m "Your commit message" - View commit history:
git log - Check the difference between commits:
git diff - Create a new branch:
git branch <branch-name> - Switch to a different branch:
git checkout <branch-name> - Merge one branch into another:
git merge <branch-name> - Push changes to GitHub:
git push origin <branch-name> - Clone a repository from GitHub:
git clone https://github.com/<username>/<repository>.git - Fetch remote changes:
git fetch origin - Pull remote changes and merge into your current branch:
git pull - Make a temporary change without committing it:
git stash(to save the changes),git stash apply(to apply them later) orgit stash pop(to both apply and delete the stashed changes). - Undo your last commit:
git reset HEAD~1(this will remove the last commit but keep the changes in the working directory) orgit reset <commit-hash>(to go back to a specific commit).
Updating Repository
git add .
git commit -m “comment”
git branch -M main
git push -u origin main
Merge