Skip to content

Instantly share code, notes, and snippets.

@iscott
Last active April 17, 2021 15:49
Show Gist options
  • Save iscott/757aeedc7ec3e34b510904c67f0542a2 to your computer and use it in GitHub Desktop.
Save iscott/757aeedc7ec3e34b510904c67f0542a2 to your computer and use it in GitHub Desktop.
Git branches and merging

Basic workflow for git branching:

Create a branch called "my_feature_branch" and change your git to working on that branch:

git checkout -b my_feature_branch

The branch is an exact clone of what master was when you ran the command.

Work as usual, however all edits will live in that feature branch only -- they won't affect master.

If you want to throw out the changes, just git checkout master.

  • And you'll be back on the main branch with no changes

  • To get back to your feature branch: git checkout my_feature_branch

If you want to merge your changes into the master branch:

On the my_feature_branch branch:

git add -A
git commit -m "message goes here"

then to merge in the changes from the jamie branch:

git checkout master to switch back to the master branch
git merge my_feature_branch

You've successfully merged in your feature branch changes. At this point you can leave your feature branch in the git repo, or delete it to merge the history back into master.

Deleting the feature branch (after changes are merged into master):

git branch -d my_feature_branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment