Jon Rumsey

An online markdown blog and knowledge repository.


Project maintained by nojronatron Hosted on GitHub Pages — Theme by mattgraham

Git Cheatsheet

Keep a record of learned GIT tricks and traps.

Checkout Workflow

CSharp Fritz used this flow on his Twitch stream one day:

  1. Checkout a new branch: git checkout -b {branch-name}
  2. Set upstream to remote: git push -u origin {branch-name}
  3. Stage changed files: git add {...filename | .}
  4. Commit staged changes and add a comment: git commit -m '{50-char-un-truncated-comment}
  5. Push changes to remote: git push

Key Takeaways:

Set Upstream

Two common ways:

  1. When setting up a new branch.
  2. When adding a remote branch to your local.

Set Upstream To New Branch

  1. git checkout -b {branch-name}
  2. git push -u origin {branch-name}
  3. Start deving and git flowing.

Add Remote Branch To Local

  1. git checkout -b {remote-branch-name}
  2. git branch --set-upstream-to={remote}/{remote-branch-name} {remote-branch-name}

For example:

  1. git checkout -b staging
  2. git branch --set-upstream-to=origin/staging staging

Tagging

  1. Set a tag at the current commit: git tag {new-tag-name}
  2. Push tag(s) to remote: git push upstream main

Key Takeaways:

Git Reset

Usage example git reset --{option} {commit_hash}:

Options:

Return to ContEd Index

Return to Root README