Git Source Code Management

Source Code Management Using Git

Web designers and application developers can use Git to track changes or versions. Git is a distributed version control system (dvcs). Every repository (local copy of source code) contains the complete history therefore rendering a central server redundant or network independent.

The focus of this tutorial will be on setting up two repositories. The remote repository can be located on a remote server or local disk drive. The local repository will refer to the version were changes are made on the local machine.

This tutorial uses Git for source code management. Git is cross-platform compatible (Unix, Linux, MacOS and Windows). Git can be downloaded from git-scm.com

    Tools are required:

  • Text editor (preferable command line).
  • Secure Shell (SSH) Client.
  • Shell Access (command line).
  • Git.

Create Git Server

## ASSUMING DEBIAN LINUX BASED SYSTEM ##
# SSH into remote server #
ssh remoteUser@remoteServer
# Optional Determine IP address #
sudo ifconfig
# Optional Determine domain name #
cat /etc/hosts
# Install Git #
sudo apt-get install git
# Create Repository Folder #
mkdir newRepo.git
# Enter Repository Folder #
cd newRepo.git
# Initialize Repository Without Working Folder #
git init --bare

Use your favourite SSH client to connect to your remote server. If you are using a local machine, determine if IP address or domain name. Install Git. Create a folder to hold the repository. Initialize the repository using Git.

Create Local Repository

## ASSUMING DEBIAN LINUX BASED SYSTEM ##
# Install Git #
sudo apt-get install git
# Create Repository Folder #
mkdir newRepo
# Enter Repository Folder #
cd newRepo
# Initialize Repository As Working Folder #
git init

Install Git. Create a folder to hold the local repository. Initialize the repository using Git..

Connect To Remote Repository

## BY DEFAULT GIT USES SSH ##
# Connect To Remote Server #
git remote add origin remoteUser@remoteServer:newRepo.git

By default the remote server repository is called the master branch. The command “git remote add origin” must be ran at least once so that the remote information can be stored.

Add First File To New Repository

echo "Ojambo.com First File" > Readme.txt

The Readme.txt file can be created using any text editor. The “echo” command was used to speed up the process of created a simple text file using the command line. The “echo” command is cross-platform compatible.

Commit & Push Changes To Remote Server

git add .
git commit -m "Initial Commit"
git push origin master

Let git know which files are to be pushed using the “git add” command. Add a message for the committed files using the “git commit -m” command. Push the changes using the “git push” command and specifying the location which is master in this tutorial.

Demonstration:

Ojambo.com Source Code Management Using Git Tutorial

Image Missing
Ojambo.com Git Remote Server Prompt

Image Missing
Ojambo.com Git Local Branch Prompt

Conclusion:

Git is a popular source code management system. Git is a distributed revision control system because every “working directory” contains the complete history and therefore revision tracking capabilities. A central server is not required for Git to work.

Git can work on remote servers or local machines. Git can push changes committed changes when the network is available.

    Recommendations:

  1. Use descriptive names for the remote server repository folders.
  2. Use SSH protocol with Git.