Skip to content

Instantly share code, notes, and snippets.

@zytron
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save zytron/f29efed89e1c3ea601bb to your computer and use it in GitHub Desktop.

Select an option

Save zytron/f29efed89e1c3ea601bb to your computer and use it in GitHub Desktop.
Git workflow
# Create a new branch that forks off remote master
$ git checkout -b mybranch origin/master
# Make changes and commit to branch (you can use -m on command line to specify commit message, or leave it off and use your default editor to write your commit message when it prompts)
$ touch a.txt
$ git add a.txt
$ git commit -m "Added file"
$ vi a.txt
$ git add a.txt
$ git commit -m "Updated file"
... more changes and commits
# Get all changes other people have committed to master
$ git fetch origin
$ git pull origin master
# Choices here:
1) Keep all commits, including all the minor inconsequential ones that nobody will care about like "Added a file" and leave commit time alone, so your commits will intersperse with other people's commits depending on time
$ git checkout master
$ git pull origin master
$ git merge mybranch
$ git push origin master
2) Keep all commits, but "rebase" so that all your commits appear to have been done in one chunk
$ git checkout mybranch
$ git pull --rebase origin/master
$ git checkout master
$ git pull origin master
$ git merge mybranch
$ git push origin master
3) Squash all minor commits, to keep only major commits/reword commit message (loses your commit history)
$ git checkout mybranch
$ git pull origin master
$ git rebase -i origin/master
... select reword for top commit and squash others
... write commit message when prompted
$ git checkout master
$ git pull origin master
$ git merge mybranch
$ git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment