Skip to content

Instantly share code, notes, and snippets.

@SabaPing
Forked from jednano/gitcom.md
Created April 1, 2019 03:43
Show Gist options
  • Select an option

  • Save SabaPing/c21c36bdbff2cc8a2e42d0630cba0f1c to your computer and use it in GitHub Desktop.

Select an option

Save SabaPing/c21c36bdbff2cc8a2e42d0630cba0f1c to your computer and use it in GitHub Desktop.
Common git commands in a day-to-day workflow

Initial Setup

Create an empty git repo or reinitialize an existing one

Click the "Fork" button at the top-right of any repository's GitHub page.

Clone the codepainter repo into a new directory called codepainter:

$ git clone https://github.com/jedhunsaker/codepainter.git codepainter

Checkout a remote branch with tracking.

git checkout --track -b <branch> origin/<branch> -B to force it.

Checkout fork's master branch with upstream/master as remote.

git checkout -b master upstream/master

Push a local branch for the first time.

git push --set-upstream origin <branch>
git push

Push a local branch to a different remote branch.

git push origin <local-branch>:<remote-branch> -f to force it.

Squash a number of commits into a single commit.

git rebase -i HEAD~<number-of-commits>

Commit all changes with a message.

git commit -am <msg>

Remove a local branch.

git branch -d <local_branch> -D to force it.

Remove a remote branch.

git push origin :<remote_branch>

Manually set tracking.

git config branch.<local_branch>.remote origin
git config branch.<local_branch>.merge refs/heads/<remote_branch>

Do a pull, stacking your recent commits on TOP of the pulled commits.

git pull --rebase

Undo last push

git reset --hard HEAD~1 && git push -f origin master

Rebase on upstream master

git fetch upstream && git rebase upstream/master

List the set of repositories ("remotes") whose branches you track.

git remote -v

Checkout as CRLF, Commit as LF

git config --global core.autocrlf true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment