Friday, July 14, 2017

Source code revision control with Git

Version control system is used to manage versions of files and is used widely with programming source codes. Common examples are SVN and Git.

Here is an example of the using GIT with Heroku (Working with GIT2). It demonstrates the git command for;
  • clone
  • branch
  • checkout
  • commit
  • status

Basic commands to manage a local version control repository

Typical process to prepare a folder where files are to be tracked/staged uses the commands init, status and add. It would be good to have created a folder with 4 or 5 files and try out the following commands.
 # Initialise Git repository   
  $ git init   
  # Identify status and which files are being track or untracked.   
  $ git status   
  # Add all files to the repository   
  $ git add .  
 # Identify files are being track as staged  
  $ git status   

At this time, a folder to manage the repository is created with the name ".git". Have a look at content of the files in this folder.

Filename: .git/HEAD
ref: refs/heads/master

Filename: .git/config
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly

Filename: .git/description
Unnamed repository; edit this file 'description' to name the repository.

To remove a file from being tracked.
 # Remove a file from list of staged files  
 $ git rm --cached somefile.txt.  

Process to place files into the repository.
 # Commit files to repository  
 $ git commit -m "Place comments here"  
 $ git status  

Retrieve tracked file from the repository. The latest thats found in the repository, that is.
 # Checkout a file from the repository  
 $ git checkout programming.txt  
 $ git status  

Cache and other files that should not be kept in the repository or tracked, can be listed in a file ".gitignore" within that folder. Example to ignore the folder "temp" and file "nofile.txt".

Filename: .gitignore