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.

Tags: , , , , , , , ,

This entry was posted on Wednesday, February 13th, 2013 at 12:00 am and is filed under Tips & Tricks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Git Source Code Management”

  1. Ojambo Gitweb Git Web Interface Says:

    March 20th, 2013 at 12:01 am

    […] Git install instructions are available at Ojambo.com Git Source Code Management. […]

  2. Ojambo Git Source Code Management Video 0050 Says:

    March 29th, 2013 at 12:01 am

    […] Video for the Ojambo.com Git Source Code Management article. Part One of […]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>