cheatsheets

Git Cheat Sheet

Useful links

Local

git init ## initialise a new git repo
git add . ## add all files in the directory to git repo
git add "filename" ## add specific file to the git repo
git status ## check the status of files in the git repo
git commit -m "message" ## commit your working code to the git repo with a message
git commit --amend --no-edit ## amend last commit without creating another one with for example small change
git reset --hard HEAD^ ## go back to commit before last

Remote

git remote add origin "http://github.com/foo" ## add a remote repo to synch your local repo with
git pull "http://github.com/foo" main ## synch your local repo with a remote repo
git push origin main ## push your locally committed changes to the remote repo
git pull ##pull any changes made in the remote repo to your local repo

Branch and Commit Management

git log --oneline ## see commits
git branch branch-name ## create new branch
git checkout branch-name ## checkout the branch
git merge other-branch ## merge other-branch into current branch
git branch --list ## what branches are there in the repo
git log -v ## see the change history in a branch
git log -p ## see actual change for a commit
git reset --hard {versionid} ## revert to previous version
git branch -D branch-name ## hard deletes branch even if not merged

Setup local git config

You can find your git configuration file in C:\Users{username}.gitconfig.

[user]
    name = HUNGOVER CODER
    email = info@hungovercoders.com
git config --global user.name "HUNGOVER CODER"
git config --global user.email "info@hungovercoders.com"
git config --global http.proxy
http://proxyUsername:proxyPassword@proxy.server.com:port

Conventional Commits

Format

<type=feat|fix|perf|build|ci|chore|docs|refactor|revert|style|test>[(optional scope)]: <description, imperative, present tense, lowercase, no dot at end>

[
  Optional body section.

  Motivation for the change and contrast with previous behaviour.

  Can span multiple lines.
]

[BREAKING CHANGE: :warning: <description, imperative, present tense, lowercase, no dot at end>]

[Closes / Fixes #123, #456, #789]

[
  - Additional links and meta-information
  - Additional links and meta-information
  - Additional links and meta-information
]

Types

Type Meaning Description
feat Features A new feature
fix Bug fixes A bug fix
docs Documentation Documentation only changes
style Styles Changes that do not affect the meaning of the code
refactor Code Refactoring Code change neither fixes a bug nor adds a feature
perf Performance Improvements Code change that improves performance
test Tests Adding missing tests or correct existing tests
build Builds Changes that affect build or deployment pipelines
chore Chores Other changes that don’t modify src or test files
revert Reverts Reverts a previous commit

VS Code Quick Workflow

Following ensures use of conventional commits and automatic syncing on commit!