Monday, March 10, 2014

Git Workflow for Local and Remote Repository

Typical workflow for two developer that clone/fetch/push to a remote git repo. Each developer use one tracking branch. Once changes are pushed to remote repo we use rebase twice to merge the local branches into the master branch.



step 1
on remote machine:
add some files on master branch and create commit with message initial commit and then:

~/Documents/repos/news_site (master)$ git branch arm
~/Documents/repos/news_site (master)$ git branch ral

step 2
on developer machine A:

~$ git clone ssh://remote_user@example.com/home/remote_user/Documents/repos/news_site news
~$ cd news/
~/news (master)$ git fetch
~/news (master)$ git checkout -b ral origin/ral
Branch ral set up to track remote branch ral from origin.
Switched to a new branch 'ral'
~/news (ral)$ vim ral.js
~/news (ral)$ git add ral.js 
~/news (ral)$ git commit -m 'added ral.js file'
~/news (ral)$ git push origin

step 3
on developer machine B:

~$ git clone ssh://remote_user@example.com/home/remote_user/Documents/repos/news_site news
~$ cd news/
~/news (master)$ git fetch
~/news (master)$ git checkout -b arm origin/arm
Branch arm set up to track remote branch arm from origin.
Switched to a new branch 'arm'
~/news (arm)$ vim arm.js
~/news (arm)$ git add arm.js 
~/news (arm)$ git commit -m 'added arm.js file'
~/news (arm)$ git push origin

step 4
Back on remote machine

~/Documents/repos/news_site (master)$ git rebase ral
~/Documents/repos/news_site (master)$ git rebase arm
~/Documents/repos/news_site (master)$ git log  --pretty=format:"%h - %an, %ar : %s"
62abec1 - Ralph Schweitzer, 23 minutes ago : added ral.js file
fbb4085 - Armand Belisle, 25 minutes ago : added arm.js file
9aa592e - John Bower, 21 hours ago : initial commit

In this example rebase is safe since the developers worked on different files.

No comments:

Post a Comment