Technologist

Tech stuff about Cloud, DevOps, SysAdmin, Virtualization, SAN, Hardware, Scripting, Automation and Development

Browsing Posts in Development

“Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.” –http://git-scm.com/

In this guide I will walk you through setting up a Git server and accessing it from a Git client over SSH.

Git Server
I am using CentOS 5.3 as my server.
Hostname: gitserver.example.com
SSH Port: 22444 (As opposed to the default port 22, for increased security)

Install Git

yum install git

Create a folder where you will keep the repositories

mkdir /opt/git

Create a git user and change the owership and permissions of the previously created folder to the new user

useradd -c “Git Repository” git
chown git:git git:git /opt/git/
chmod 770 /opt/git

Create an empty project, I am calling my project ‘myproject’

mkdir /opt/git/myproject.git

Initialize the repository using –bare to only include objects at the server side

cd /opt/git/myproject.git
git –bare init

You are done with the Git server, let’s take a look at the client

Git Client
Install Git on your client.

Debian/Ubuntu:
sudo apt-get install git-core

Red Hat/Centos:
yum install git (I am using the rpmforge repo)

Now it’s time to version-control your project.

Create a new folder to put your code (unless it exists already)

mkdir /home/john/myproject

Now it is time to add your project to Git (locally):

cd /home/john/myproject
git init

Add all the files in the current directory to be source controlled:
git add *

Commit the changes:
git commit -m “Myproject first commit”

Tell the Git client where to find the server and remote repository

git remote add origin ssh://git@gitserver.example.com:22444/opt/git/myproject.git

Push your project to the server

If you have shared SSH keys:
git push origin master

OR If you dont have configured SSH keys:
git push ssh://git@gitserver.example.com:22444/opt/git/myproject.git master

Now your project is under Git source control


Pull/Clone project:

The below will download the project folder in the current folder:

git clone ssh://git@gitserver.example.com:22444/opt/git/myproject.git

When you make changes to your project, you need to tell Git about it and commit the changes:

cd /home/john/myproject
git add *
git status (Check status)
git commit -a -m “A comment describing the change”

The following PowerShell one liners will help you in getting a list of files and/or folders in a given folder.
It can be useful to capture this information in a text file for later processing or even a spreadsheet.

PowerShell is very powerful in that it returns objects that you can manipulate.

For Example, to return the list of ONLY directories on the C:\ drive:

PS C:\> Get-ChildItem | where {$_.PsIsContainer}

Mode LastWriteTime Length Name
—- ————- —— —-
d—- 3/12/2009 12:28 PM Projects
d—- 6/10/2010 9:38 AM cygwin
d—- 9/21/2010 7:02 PM Documents and Settings

Get-ChildItem can be run with no arguments to get all items, just like a ‘dir’ command.
In fact, dir, ls, gci are aliases of the Get-ChildItem cmdlet.

In the following example, I will get the list of ONLY the directories and then from this I will take only the name. Also, I will use the alias ‘dir’

PS C:\> dir | where {$_.PsIsContainer} | Select-Object Name

Name
—-
Projects
cygwin
Documents and Settings

If you wish to get the list of ONLY files, you just need to negate the where condition:
where {!$_.PsIsContainer}

PS C:\> Get-ChildItem | where {!$_.PsIsContainer} | Select-Object Name

Name
—-
.rnd
AUTOEXEC.BAT
CONFIG.SYS
cygwin.lnk
install_log

You can redirect this output to a text file for later processing:

PS C:\> Get-ChildItem | where {!$_.PsIsContainer} | Select-Object Name > onlyFiles.txt

Now let’s take it one step further and send this output to a CSV(Comma Separated Values) file.

PS C:\> Get-ChildItem | where {!$_.PsIsContainer} | Select-Object Name | Export-Csv onlyFiles.csv