Skip to content

Instantly share code, notes, and snippets.

@keikoro
Last active April 12, 2017 16:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keikoro/be0263fe4d45b3adac41 to your computer and use it in GitHub Desktop.
Save keikoro/be0263fe4d45b3adac41 to your computer and use it in GitHub Desktop.
git – personal cheat sheet

Committing

empty initial commit
$ git commit --allow-empty -m "initial commit"

Branches

create a "blank" branch (coming from an existing branch)
and remove all files and directories in the current directory
$ git checkout --orphan newbranch
$ git rm -rf .

Branch tracking

locally track a branch already on the remote
$ git checkout -b localbranch origin/remotebranch

remotely track a brand new local branch
$ git checkout -b localbranch
$ git push origin localbranch:remotebranch

same as above, but with simultaneous push
$ git push -u origin branchname

push only some commits to a new remote branch
~n = skip the n most recent commits
$ git push origin localbranch~n:refs/heads/remotebranch

delete a remote branch
$ git push origin :branchname

delete a local branch
$ git branch -d branchname

update the branches shown for a remote
$ git remote prune origin

stop deleted remote branches from continuing to show up locally
$ git remote update origin --prune

Diff

for files already staged
$ git diff --cached
$ git diff --staged

Unstage

individual files
$ git reset myfolder/myfile

Amending

edit commit message of last commit
$ git commit --amend

replace commit message of last commit
$ git commit --amend -m "new commit message"

change author of last commit
$ git commit --amend --author "First Last <mailaddress@provider.com>"

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