This is a cheat sheet for git commands and git workflows.
- Create a new branch and checkout to that:
git checkout -b branch-name- Checkout to an existing branch:
git checkout branch-name- Delete a branch:
git branch -D branch-name- List only local branches:
git branch- List only remote branches:
git branch -r- List all branches (local + Remote):
git branch -a- Show branches with last commit info (more detailed):
git branch -vvCommand:
git statusExample Response:
On branch feature/responsive-util-menu
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: client/src/components/UtilMenu.tsx
no changes added to commit (use "git add" and/or "git commit -a")- Check out from the current branch and create a new branch.
git checkout -b type/name- After finishing the work
git add .
git commit -m "type: short description about the work you have done."- Push the branch to the remote so it is backed up.
git push -u origin type/name- Then open a PR (Pull Request) if you are done.
- Merge to main according to team rules and permissions.
You can easily come back because your main is untouched.
git checkout mainYou can again go to the main branch.
git checkout mainYou can also delete the previous branch.
git branch -D type/name