Everyday git commands

This blog post is about git commands I often use. I won’t describe them in depth. If more information is required you can always read the docs.

Commands

most used:

  • git fetch
  • git push
  • git checkout . => undo of local changes

commit:

  • git commit -am “some message”

list local branches:

  • git branch

create a branch:

  • git checkout -b <branch-name>

deleting branches:

  • git branch -d <branch-name> i.e. git branch -d feature/blader

delete remote branch:

  • git push–delete
    • git push origin –delete dev

housekeeping remotes:

  • git remote prune origin

reset and sync local repository with remote branch:

  • git fetch origin
  • git reset –hard origin/master
  • git clean -f -d

renaming and keeping git history:

  • in root directory of project
    • git mv <src-dir> <target-dir>
    • samples:
      • git mv packages/core/src packages/core/lib
      • git mv packages/core/lib projects/core/src

That’s it! This post may change over time so bear with me.

Thomas