Skip to content

Instantly share code, notes, and snippets.

@nikileshsa
Forked from santosh79/Git workflow.md
Last active January 20, 2018 17:32
Show Gist options
  • Save nikileshsa/29a72ad2a700fabfe3ac113e845bb65b to your computer and use it in GitHub Desktop.
Save nikileshsa/29a72ad2a700fabfe3ac113e845bb65b to your computer and use it in GitHub Desktop.

When you begin working on a feature

Step 1: Update the main branch

   git checkout master
   git pull origin master

Step 2: Create a feature branch off of the main branch

   git checkout -b my_feature_branch master

Step 3: Record/Commit your work

   ... make some code changes ...
   git commit -m 'my work' (This is an example - **don't copy paste this**)

Step 4: Keep rebasing your feature branch off the main branch

This will ensure that your feature branch is up-to-date with the main branch and has all of it's code

   git stash
   git checkout master
   git pull origin master
   git checkout my_feature_branch
   git rebase master
   git stash pop

When you are doing the rebase, you may run into merge conflicts. Don't get spooked by merge conflicts. Resolve, them one-by-one and then run git rebase --continue after resolving each merge conflict.

Step 5: You are done

Now you are ready to merge in your changes into the mainline (master branch). Repeat step 4 -- to ensure you have all of the mainline code. Then do:

   git checkout master
   git merge --no-ff my_feature_branch
   git push origin master

If the push fails do git reset --hard origin/master and then repeat Steps 4 and 5.

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative somefile

@nikileshsa
Copy link
Author

git reset --hard ORIG_HEAD - to undo a merge from pull

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