Skip to content

Instantly share code, notes, and snippets.

@saveologypaul
Created May 11, 2012 16:23
Show Gist options
  • Save saveologypaul/2660750 to your computer and use it in GitHub Desktop.
Save saveologypaul/2660750 to your computer and use it in GitHub Desktop.
Git Workflow without merge conflict
How to make a feature with git and branches:
paul@dev:~/Sites/myapp(master)$ gpr #make sure your master branch is up todate with github
paul@dev:~/Sites/myapp(master)$ bundle #make sure all gem/plugins are installed
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.7)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.7)
Using erubis (2.6.6)
Using rack (1.2.5)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using actionmailer (3.0.7)
Using arel (2.0.10)
Using activerecord (3.0.7)
Using activeresource (3.0.7)
Using rubyzip (0.9.7)
Using selenium-webdriver (0.2.1)
Using capybara (0.4.1.2)
Using carrierwave (0.5.3)
Using haml (3.1.2)
Using ruby-debug19 (0.11.6)
Using sass (3.1.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
paul@dev:~/Sites/myapp(master)$ up #make sure database is up to date
paul@dev:~/Sites/myapp(master)$ gb #check your current branches
test_branch
* master
paul@dev:~/Sites/myapp(master)$ gb new_feature #add a new branch by the name of your new_feature
paul@dev:~/Sites/myapp(master)$ gb #check your branches and you should see new branch you created
new_feature
test_branch
* master
paul@dev:~/Sites/myapp(master)$ gco new_feature #check out that branch you created
paul@dev:~/Sites/myapp(new_feature)$ gb #check that you are currently in the new_feature branch
* new_feature
test_branch
master
paul@dev:~/Sites/myapp(new_feature)$ vim ./features/my_new_feature.feature #write a test
paul@dev:~/Sites/myapp(new_feature)$ cucumber features/my_new_feature.feature #run your feature file and watch it fail
paul@dev:~/Sites/myapp(new_feature)$ rails generate migration AddPartNumberToProducts part_number:string #create a migration if you need to add database fields
paul@dev:~/Sites/myapp(new_feature)$ up #run migrations with up or use (rake db:migrate db:test:prepare)
paul@dev:~/Sites/myapp(new_feature)$ cucumber features/my_new_feature.feature #write code until your feature passes with green
paul@dev:~/Sites/myapp(new_feature)$ gst #see what files have changed with git status
# On branch new_feature
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# added: features/my_new_feature.feature
# modified: app/controllers/pages_controller.rb
# modified: app/views/pages/test.html.haml
#
no changes added to commit (use "git add" and/or "git commit -a")
paul@dev:~/Sites/myapp(new_feature)$ git add . #add all changed files to commit
paul@dev:~/Sites/myapp(new_feature)$ gst #check to see that files have been staged to commit into local repo
# On branch new_feature
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# added: features/my_new_feature.feature
# modified: app/controllers/pages_controller.rb
# modified: app/views/pages/test.html.haml
#
paul@dev:~/Sites/myapp(new_feature)$ gc -m '[Finishes #5786847] Added New Feature' #commit with the pivitol tracker number
paul@dev:~/Sites/myapp(new_feature)$ gco master #before you merge code switch to master and update from github
paul@dev:~/Sites/myapp(master)$ gpr #git pull rebase to make sure other team members code is applied in proper order
remote: Counting objects: 63, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 48 (delta 33), reused 48 (delta 33)
Unpacking objects: 100% (48/48), done.
From github.com:miamiphp/myapp
aca2e28..ecc65d8 master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: Adding login
paul@dev:~/Sites/myapp(master)$ bundle #make sure gems are installed if any were added from other developers
paul@dev:~/Sites/myapp(master)$ up #make sure to update database if any were added from other developers
paul@dev:~/Sites/myapp(master)$ gco new_feature #return to your feature branch
paul@dev:~/Sites/myapp(new_feature)$ git rebase master #merge in new changes from other developers
paul@dev:~/Sites/myapp(new_feature)$ rake #run FULL TEST SUITE (rspec & cucumber) fix if not green and run rake again
paul@dev:~/Sites/myapp(new_feature)$ gco master #switch to master branch
paul@dev:~/Sites/myapp(master)$ git merge new_feature #merge in your changes
paul@dev:~/Sites/myapp(master)$ gp #push your changes to github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment