Git - SCM

project visualizationSoftware configuration management (SCM) is important even with a relatively small project and even more so with a large project with multiple contributors.  Git is a widely adopted sophisticated system allowing for distributed control, local branching, staging areas, and multiple workflows.  It integrates with many cloud based, Git aware project management platforms such as SaaS hosted Github, Bitbucket, Gitlab, Kiln and self hosted Redmine.  There are other services as well as other SCM. 

Assuming that you already have Git installed, reference the figure to the right.  The numbers in the colored boxes could reference stakeholder issues.  Note in the examples below many git responses are omited.

The version of Git that the examples in this article used is:


$ git --version
git version 2.2.1 # Not mandatory but it customizes your commits $ git config user.email myname@mywebsite.biz $ git config user.name firstName lastName

1. Initialize the project from the command line in a linux terminal, or from the git bash emulator in Windows.


$ mkdir my_project && cd my_project
$ git init
# shortcut way to create and edit the first file $ echo 'My Project Information' >> readme.md

$ git add readme.md
$ git commit -m '#1'
$ git status

2. Create a new branch and switch to add code written for a new feature to be commited.


$ git branch feature23
$ git checkout feature23

# create a new directory and write some javascript
$ mkdir js && cd js
$ echo '//Example application commit #2' >> app.js
$ cd ..
$ git status
$ git add js
$ git commit -m '#2'
$ git status

3. On the same branch make another change to your app


$ cd js
$ echo 'alert("Commit #3");' >> app.js
$ git status
$ git add app.js
$ git commit -m '#3'

Review your progress.

$ git log --oneline --decorate --graph --all

4. Make a comment in the readme file then merge branch 'master' with branch 'feature23'


$ cd ..
$ git checkout master
$ echo 'Issue 4 - Release deadline merging here' >> readme.md
$ git status
$ git add readme.md
$ git commit -m '#4'
$ git merge feature23 -m '#4'

Review project progress. It should be starting to look somewhat like the figure referenced above.


$ git log --oneline --decorate --graph --all

*   b968c4d (HEAD, master) '#4'
|\  
| * cfc49e1 (feature23) #3
| * c55e7fa #2
* | d340a45 #4
|/  
* 0967617 #1

Not want you wanted? Try undoing the merge with the command 'git reset --merge ORIG_HEAD' .

T1.0.0 Communicate the important merge with a tag that complies with semantic versioning. and inspect the added tag and changes to the log.


$ git tag -a T1.0.0 -m "API public release T1.0.0"
$ git tag
$ git log --oneline --decorate --graph --all
$ git show T1.0.0

6. (intentionally out of numerical sequence) a simple change that does not affect the API.


$ git branch feature67
$ git checkout feature67
$ cd js
$ echo '//Issue #6 simple change that does not affect API ' >> app.js
$ git add app.js
$ git commit -m '#6'

7. A change that does affect the API.


$ echo 'alert("Issue #7 affects API"); ' >> app.js
$ git add app.js
$ git commit -m '#7'

5. A change that should bring about world peace asap.


$ git branch feature58
$ git checkout feature58
$ echo '//Issue #5 bring about world peace asap ' >> app.js
$ git add app.js
$ git commit -m '#5'

8. Calling for peace recursiving will crash the app.


$ echo '//Issue #8 a wild goose chase ' >> app.js
$ echo 'function peace(){peace();};peace();' >> app.js
$ git add app.js
$ git commit -m '#8'

9. Make a comment in the readme file then merge branch 'master' with branch 'feature67'


$ git checkout master
$ echo 'Issue 9 - Release deadline merging here' >> readme.md
$ git status
$ git add readme.md
$ git commit -m '#9'
$ git merge feature67 -m '#9'
$ git log --oneline --decorate --graph --all

T2.0.0 Communicate the important merge with a tag that complies with semantic versioning. and inspect the added tag and changes to the log.


$ git tag -a T2.0.0 -m "API changed so soon! T2.0.0"
$ git tag
$ git log --oneline --decorate --graph --all
$ git show T2.0.0

10. A deadend for the issues 5,8 calling for world peace asap.


$ git checkout feature58
$ echo '//Issue #10 peace() calling peace() leads to too much recursion ' >> app.js
$ git add app.js
$ git commit -m '#10 discontinued this line of reasoning'



Conclusion. Inspect the results


$ git log --oneline --decorate --graph --all
* 1d23774 (feature58) #10 discontinued this line of reasoning
* 9254e7b #8
* 267c5f1 #5
| * 09ec02b (HEAD, tag: T2.0.0, master) #9
| |\
| |/
|/|
* | 4a9aa93 (feature67) #7
* | 0470637 #6
| * 6a42f29 #9
|/
* b968c4d (tag: T1.0.0) '#4'
|\
| * cfc49e1 (feature23) #3
| * c55e7fa #2
* | d340a45 #4
|/
* 0967617 #1

If you want to keep the project for future reference, why not?  However if you would like to delete it for ever, never to get it back then you can change into the upper level directory that contains my_project and issue the command rm -rf my_project. The directory and all the files will be gone forever.

For more details consider Git in terms of your project workflow and code deployment to a website.


Reference:

code highlighting: http://vividventures.biz/d/?q=highlightjs

Deploying website with git:  https://christian.skala.me/blog/using-git-to-deploy-a-web-site/