Skip to content

Instantly share code, notes, and snippets.

@Nothing-Works
Last active June 9, 2020 08:39
Show Gist options
  • Select an option

  • Save Nothing-Works/20f6b29c6a2d04d4dfd1536531e39268 to your computer and use it in GitHub Desktop.

Select an option

Save Nothing-Works/20f6b29c6a2d04d4dfd1536531e39268 to your computer and use it in GitHub Desktop.
some git workflow

sync fork with upstream

  1. Add the remote, call it "upstream":
git remote add upstream https://github.com/whoever/whatever.git
  1. Make sure that you're on your master branch:
git checkout master
  1. Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:
git fetch upstream
  1. Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch:
git rebase upstream/master or git merge upstream/master

Note: 3 and 4 can be simplified by

git pull upstream master or git pull --rebase upstream master
  1. If your git history has been rewritten, you need force push. Otherwise a normal push will do.
git push -f origin master or git push origin master

basic rebase workflow

  1. get the latest from remote
$ git checkout master
$ git pull or git pull --rebase
  1. develop by creating a new branch
$ git checkout -b pr-cool-feature
  1. DO THE WORK!!!

  2. When you are done. get the updates again.

$ git checkout master
$ git pull or git pull --rebase

if open source project or similar nature

$ git fetch upstream
$ git rebase upstream/master

and then push

  1. rebase from feature branch, you may also resolve any conflict and squash commits
$ git checkout pr-cool-feature
$ git rebase master
  1. rebase from master
$ git checkout master
$ git rebase pr-cool-feature
  1. then push it
$ git push

git tags

  1. add tag
git tag <tagname>

git tag -a <tagname> -m '<message>'
  1. push tag/tags
git push origin <tag_name> // single tag

$ git tag                         # see tag lists
$ git push origin <tag-name>      # push a single tag
$ git push --tags                 # push all local tags 

Delete Branch

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

Useful config/command

$ git config --global push.default current
$ git config --global pull.rebase true

$ git push origin pr-cool-feature  # push the current branch to orgin
$ git push origin HEAD             # push the current branch to orgin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment