Md-Mahir-Asef / git-cheatsheet

This is a cheat sheet for git commands and git workflows.

Repository from Github https://github.comMd-Mahir-Asef/git-cheatsheetRepository from Github https://github.comMd-Mahir-Asef/git-cheatsheet

Git Cheatsheet

This is a cheat sheet for git commands and git workflows.

Common Git Commands

Branches

  1. Create a new branch and checkout to that:
git checkout -b branch-name
  1. Checkout to an existing branch:
git checkout branch-name
  1. Delete a branch:
git branch -D branch-name
  1. List only local branches:
git branch
  1. List only remote branches:
git branch -r
  1. List all branches (local + Remote):
git branch -a
  1. Show branches with last commit info (more detailed):
git branch -vv

Status

Command:

git status

Example 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")

Git Workflows

Git Branch Workflow

  1. Check out from the current branch and create a new branch.
git checkout -b type/name
  1. After finishing the work
git add .
git commit -m "type: short description about the work you have done."
  1. Push the branch to the remote so it is backed up.
git push -u origin type/name
  1. Then open a PR (Pull Request) if you are done.
  2. Merge to main according to team rules and permissions.

If you need to back out before the merge.

You can easily come back because your main is untouched.

git checkout main

You can again go to the main branch.

git checkout main

You can also delete the previous branch.

git branch -D type/name

About

This is a cheat sheet for git commands and git workflows.