20161001

Git

A Git IT work in progress....
  1. Installing Git
    1. Install from the CLI
      1. $ sudo apt-get install git-all
    2. First-Time Git Setup
      1. Configure your user info
        1. $ git config --global user.name "John Doe"
        2. $ git config --global user.email johndoe@example.com
      2. Configuring your editor
        1. $ git config --global core.editor gedit
      3. Checking Your Settings
        1. $ git config --list
  2. Getting a Git Repository
    1. Initializing a Repository in an Existing Directory
      If you’re starting to track an existing project in Git, you need to go to the project’s directory and type:
      1. $ git init
      2. $ git add *
      3. $ git add .
      4. $ git commit -m 'initial project version'
    2. Cloning an Existing Repository
      1. $ git clone https://github.com/source/git/dir target/git/dir
      2. Git has a number of different transfer protocols you can use.
    3. Initializing Git repositories in the Cloud
      This was something that I needed to do (for my own personal and private projects). While there are many ways out there to host your private repositories such as the awesome Bitbucket, Github, etc, I was looking at much simpler solution just for myself. All I needed is a versioning system to keep my source codes.

      I'm going to demonstrate how easy it is to host your own Git repositories in any of your preferred cloud providers. I chose Google Drive personally.

      Lets say you have a project named "johndoe":
      1. Initialize an empty Git repository: 
        1. $ cd /path/to/project/johndoe
        2. $ git init
      2. Make and change directory to where your Google Drive is located and initialize a bare repository.
        1. $ mkdir /path/to/GoogleDrive/project/johndoe
        2. $ cd /path/to/GoogleDrive/project/johndoe
        3. $ git remote add origin /path/to/GoogleDrive/project/johndoe
        4. $ git push origin master
    4. Cloning Git Repositories in the Cloud
      1. To clone your Git repository from Google Drive
        1. $ git clone /path/to/GoogleDrive/project/johndoe
    5. Git Version Control
      1. There are some subtleties to this because of the nature of Git. The way I've done this is by copying what the Git developers themselves do. First, you'll want to use annotated tags which is probably a good idea anyway. To review, you can create a new tag like this:
        1. $ git tag -a -m "Version 0.2" v0.2 HEAD
      2. Then you can use git describe for a useful "version" string that will include the number of commits since the tag and the leading digits of the sha1 of the the current commit. Here's an example from one of my projects:
        1. $ git describe
        2. v1.0-3-gee47184
      3. That is, this copy is 3 commits ahead of the "v1.0" tag and the commit sha1 begins with ee47184 (I'm not sure why they include that leading 'g').
      4. The Git developers take it one step further and also include an extra bit if the working copy is modified (uncommitted). This requires a few more steps so it's all wrapped up in a script they name VERSION-GEN. When run, it prints the version string to standard output and also creates a VERSION-FILE file (the script is careful to not re-touch that file if the version hasn't changed -- so it's build-tool friendly). Then, you can include that VERSION-FILE file in your source code, help files, etc.
      5. Using my example VERSION-GEN script, my version string for the above example is:
        1. $ VERSION-GEN
        2. version: 1.0-3-gee47
      6. If I modify any of the tracked files it looks like this:
        1. $ VERSION-GEN
        2. version: 1.0-3-gee47-mod
      7. Note that VERSION-GEN expects that the tags marking versions are of the form v[0-9]* (e.g., v1.0 or v0.2 or v12.3.4 or v12.2-4feb2009 etc.)
  3. Recording Changes to the Repository with RabbitVCS
    1. Installing RabbitVCS for use with Nemo