Skip to content

Instantly share code, notes, and snippets.

@kreig303
Last active June 21, 2019 15:09
Show Gist options
  • Save kreig303/095c2658a4920cedf8bcd432dce509a4 to your computer and use it in GitHub Desktop.
Save kreig303/095c2658a4920cedf8bcd432dce509a4 to your computer and use it in GitHub Desktop.
GIT FU

REMOVE LAST COMMIT

$ git reset HEAD~1
$ git push origin +HEAD

FIX REMOTE BRANCH AFTER PUSH

# reset local branch to desired commit hash
$ git checkout [local-branch-name]
$ git reset --hard abc123d4e5
# now, reset remote branch to desired commit hash
$ git push -f [remote-name] 0d1d7fc32e5a947fbd92ee598033d85bfc445a50:[remote-branch-name]

ETC

$ git log --oneline --decorate

$ git status -sb

$ git config --global branch.autosetuprebase always

$ git add -p # patch check all adds

$ git push -d <remote_name> <branch_name>
$ git branch -d <branch_name>

TAGS

$ # Add a tag
$ git tag vx.x.x HASHNUM -am ‘description.’
$ git push --tags
$ # Delete a tag
$ git tag -d 12345
$ git push origin :refs/tags/12345

also https://mislav.net/2010/07/git-tips/

Contributing to projects on GitHub

CREATE

  • [First, fork in GitHub]
$ git clone MYREPO
$ cd MYREPO
$ git remote add upstream THEIRREPO
$ git remote set-url --push upstream no_push
$ git remote -v

UPDATE

$ git fetch upstream BRANCH
$ git rebase upstream/BRANCH
$ git push

REMOVE SERIAL COMMITS (AND SAVE IN NEW BRANCH)

$ git checkout -b newbranch
$ git push -u origin newbranch
$ git checkout oldbranch
$ git reset --hard HEAD~1
$ git push origin +master

GIT FLOW

$ git flow init -d
$ git flow feature start AB-nnnn/featurename
$ git flow feature publish AB-nnnn/featurename

BRANCH SQUASH

$ git checkout master
$ git merge --squash changebranch
$ git commit -m 'Squashed feature.'
$ git push
$ git branch -D changebranch
$ git push origin :changebranch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment