Skip to content

Instantly share code, notes, and snippets.

@chaudum
Last active Mar 10, 2021
Embed
What would you like to do?

Git Workflow for Craties

1. Naming on branches

To prevent collisions of branch names, branches that are pushed to remote should be prefixed with your preferred initials, e.g. h/my-branch (for Haudi) or s/other-branch (for Spanky)

2. Create branch

Make sure you branch from the latest commit on master:

git pull
git checkout -b h/my-branch

3. Commit and push to remote

After you made your changes, commit your files locally:

git add index.html path/to/main.css
git commit -a

You can amend a commit to the previous commit:

git commit -a --amend

This will create a new commit containing changes of both commits.

Then push to remote:

git push -u origin h/mybranch

4. Rebase with master

Note: This step is only necessary, if master changed while you were working on your branch!

If there have been changes to master in the meantime, the branch needs to be rebased with master.

git fetch
git rebase origin/master
git push -f origin h/mybrach

5. Pull request

Open pull request on Github and ask a person for code review. If there are no complaints/suggestions to the pull request, the reviewer comments with ack and you can proceed with 7, otherwise 6.

6. Fixups

If there are changes to the pull request necessary, do them locally and commit them as fixups:

git commit --fixup $(git rev-parse HEAD)

This will create a new commit and mark it as fixup, so it can be squashed automatically later on.

Then, again, push to master:

git push origin h/mybranch

Proceed with 5.

7. Squash commits

If your pull request is only a single commit, you can skip this step, otherwise you will need to 'clean up' your commits by squashing them. You can use the procedure also to rename commit messages.

git rebase -i origin/master

This will launches an interactive guide. Commits that have been committed with the --fixup option are automatically marked as fixup, meaning that they are merged with the previous commit into a single commit. You can do that also manually.

When done, push your changes to remote:

git push -f origin h/my-branch

The outcome should be that you have a single commit (except you have multiple features that are clearly separate) for your pull request.

8. Merge into master

You can merge your pull request on Github.

If you prefer the command line:

git checkout master
git pull
git merge origin h/my-branch
git push origin master

Done!

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