A simple Git workflow for collaborative coding

 

git_workflow

Source Repository ⇒ https://github.com/MyOrg/test-repo
My Github account name ⇒ nisheed

1.

exponentof:~/git_base > git clone https://github.com/MyOrg/test-repo
Cloning into 'test-repo'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
Checking connectivity... done.

2.

exponentof:~/git_base > cd test-repo/
# test-repo
exponentof:~/git_base/test-repo(master) > hub fork
Updating nisheed
From https://github.com/MyOrg/test-repo
 * [new branch]      master     -> nisheed/master
new remote: nisheed

The above step forked MyOrg/test-repo under my Github account ‘nisheed’ as https://github.com/nisheed/test-repo

3.

exponentof:~/git_base/test-repo(master) > git checkout --track -b nisheed-master nisheed/master
Branch nisheed-master set up to track remote branch master from nisheed.
Switched to a new branch 'nisheed-master'

4.

exponentof:~/git_base/test-repo(nisheed-master) > git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

5.

exponentof:~/git_base/test-repo(master) > git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/MyOrg/test-repo
   9570b88..5a36d62  master     -> origin/master
Updating 9570b88..5a36d62
Fast-forward
 README.md | 2 ++
 1 file changed, 2 insertions(+)

6.

exponentof:~/git_base/test-repo(master) > git checkout nisheed-master
Switched to branch 'nisheed-master'
Your branch is up-to-date with 'nisheed/master'.

7.

exponentof:~/git_base/test-repo(nisheed-master) > git merge master
Updating 9570b88..5a36d62
Fast-forward
 README.md | 2 ++
 1 file changed, 2 insertions(+)

8.

exponentof:~/git_base/test-repo(nisheed-master) > git push
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 304 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@github.com:nisheed/test-repo.git
   9570b88..5a36d62  nisheed-master -> master

9.

exponentof:~/git_base/test-repo(nisheed-master) > vi README.md
exponentof:~/git_base/test-repo(nisheed-master) > git status
On branch nisheed-master
Your branch is up-to-date with 'nisheed/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
added a new line
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
exponentof:~/git_base/test-repo(nisheed-master) > git diff
diff --git a/README.md b/README.md
index 2f70c0e..a9b5e51 100644
--- a/README.md
+++ b/README.md
@@ -2,4 +2,6 @@

 This is a test repo and will be removed soon.

+A new line inserted.
+
 Thanks!

exponentof:~/git_base/test-repo(nisheed-master) > git commit -a -m "added a new line"
[nisheed-master 9f29678] added a new line
 1 file changed, 2 insertions(+)

10.

exponentof:~/git_base/test-repo(nisheed-master) > git push
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 327 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:nisheed/test-repo.git
   5a36d62..9f29678  nisheed-master -> master

11.

exponentof:~/git_base/test-repo(nisheed-master) > hub pull-request
https://github.com/MyOrg/test-repo/pull/1
exponentof:~/git_base/test-repo(nisheed-master) >

All the contributors of MyOrg/test-repo will be notified of this pull-request (#1). One of them will do the peer-review and merge the pull-request if the change is OK. The pull request can be viewed at https://github.com/MyOrg/test-repo/pull/1 in the above case.

Once merged the change you submitted will be available for others to pull. And the steps 4 – 11 is repeated for the next change.

4. (next cycle)

exponentof:~/git_base/test-repo(nisheed-master) > git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

5.

exponentof:~/git_base/test-repo(master) > git pull
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), done.
From https://github.com/MyOrg/test-repo
   5a36d62..e8ebc33  master     -> origin/master
Updating 5a36d62..e8ebc33
Fast-forward
 README.md | 2 ++
 1 file changed, 2 insertions(+)
exponentof:~/git_base/test-repo(master) >