Skip to content

Instantly share code, notes, and snippets.

@calaway
Last active November 18, 2024 21:22
Show Gist options
  • Save calaway/ea880263b0c0495bb00ee877f001dc59 to your computer and use it in GitHub Desktop.
Save calaway/ea880263b0c0495bb00ee877f001dc59 to your computer and use it in GitHub Desktop.
Git Workflow Best Practices

Git Branch Merging Best Practices

  1. After you've selected a feature to work on, create a branch in your local repo to build it in.
    • $ git checkout -b calaway/short_description_of_feature
  2. Implement the requested feature, make sure all tests are passing, and commit all changes in the new branch.
  3. Checkout the master branch locally.
    • $ git checkout master
  4. Pull down the master branch from GitHub to get the most up to date changes from others. If you practice git workflow as described here you should never have a merge conflict at this step.
    • $ git pull origin master
  5. Make sure all tests are passing on master and then checkout your new branch.
    • $ git checkout calaway/short_description_of_feature
  6. From your new branch, merge in your local master branch.
    • $ git merge master
  7. Resolve any merge conflicts, make sure all tests are passing on the new branch, and then commit all changes from the merge.
    • $ git add .
    • $ git commit -m "Merge in master."
  8. Push the feature branch to the remote repo.
    • git push --set-upstream origin calaway/short_description_of_feature
  9. Submit a pull request on GitHub asking to merge the branch into master.
  10. A teammate reviews the code for quality and functionality.
  11. The teammate merges the pull request and deletes your branch from GitHub.

Git Commit Message Best Practices

From the Pro Git book:

Getting in the habit of creating quality commit messages makes using and collaborating with Git a lot easier. As a general rule, your messages should start with a single line that’s no more than about 50 characters and that describes the changeset concisely, followed by a blank line, followed by a more detailed explanation. [...] It’s also a good idea to use the imperative present tense in these messages. In other words, use commands. Instead of “I added tests for” or “Adding tests for,” use “Add tests for.”

@Twisted-Code
Copy link

I've been looking to organize my workflow better. A project I created to practice with Unity3D is starting to look a bit messy (not helped by some branches that are probably due to be scrapped), and I think this will help. Thank you!

@1764531220
Copy link

So now , your feature branch is synced master that contain other college's changes. Then how do you merge in to release branch ? if you just merge your feature branch to release branch , then your merge will also contain other's commits... is it good or is there a way to only include the changes made by yourself ?

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