How to Install and Configure Basic Git Server on CentOS 6
Git has changed my life. I’m not exaggerating. I work with a lot of ‘one off’ scripts (BASH, PHP, and Python). They are spread out among systems and developed from my workstation and(sometimes) laptop. I spent 15 years keeping multiple versions and copies of the same scripts spread between systems. Looking back it seems Crazy!
While I’ve known about Git for years, but I had no idea how badly I needed it until I interviewed for a contract and the interviewer repeatedly mentioned Git as a crucial part of their development process. I admitted to him that I didn’t use it, but I would set it up myself and answer his questions in the next interview. I installed it and set out to learn the centralized Git workflow(similar to SVN; one master setup). There are other workflows and I recommend taking a look at this post if you are curious: https://www.atlassian.com/git/tutorials/comparing-workflows
Goals of this Post:
- Install and configure basic Git for centralized workflow
Add a user called ‘git'(or whatever) to handle Git request. Make a tough password.
Next we need to configure some default git options. These could be set globally on the server ‘/etc/git/gitconfig’ and in a users home directory, ‘~/.gitconfig’.
[root@git ~]# git config –global user.email johndoe@example.com
[root@git ~]# git config –global core.editor nano
Now create a directory to house our code.
Finally let’s make a soft link to the / directory for easy access. To the client code will stored/retrieved with the string, ‘git@10.1.10.10:/git/myproject’. Rather than ‘git@10.1.10.10:/home/git/code/myproject’.
Remember anything created by root user needs to change permissions back to the Git user.
Lets test it! Create a Git project directory to clone from.
[root@git git]# mkdir mycode.git
[root@git git]# touch mycode.git/README
[root@git git]#
Issue the command to initiate the Git repo.
Initialized empty Git repository in /home/git/code/mycode.git/
[root@git ~]#
Change owner & group to ‘git’.
From your remote machine clone the Git repo.
Cloning into ‘mycode’…
git@10.1.10.10’s password:
warning: You appear to have cloned an empty repository.
Checking connectivity… done.
[matt@mattcom1 git]$ cd mycode/
Create some test code.
print(“hello”)
[matt@mattcom1 mycode]$ git commit
# Please enter the commit message for your changes. Lines starting
# with ‘#’ will be ignored, and an empty message aborts the commit.
# On branch master
#
# Initial commit
#
# Changes to be committed:
# new file: hello.py
#
1 file changed, 3 insertions(+)
create mode 100755 hello.py
[matt@mattcom1 mycode]$
Now push your commit to the of the new code to the upstream git server.
git@10.1.10.10’s password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 248 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@10.1.10.10:/git/mycode.git
* [new branch] master -> master
[matt@mattcom1 mycode]$
Test your Git Repository delete the mycode directory and clone it again. You should see the file you just created and pushed.
[matt@mattcom1 git]$ ls
fabric mycode nflrank puppet python swnpc voiceip
[matt@mattcom1 git]$ rm -rf mycode/
[matt@mattcom1 git]$ git clone git@10.1.10.10:/git/mycode.git
Cloning into ‘mycode’…
git@10.1.10.10’s password:
remote: Counting objects: 3, done.
Receiving objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Checking connectivity… done.
[matt@mattcom1 git]$ ls mycode/
hello.py
[matt@mattcom1 git]$
Thank you for reading! Please comment if you have questions.
No Comments »
RSS feed for comments on this post. TrackBack URL