Saturday, March 1, 2014

GIT 101

I apologize in advance. I'm a lot more familiar with svn.

In the process of playing with git, I put together some steps on how to accomplish some basic git tasks. The main goal is to set up a repository on a server and get your developer stations synching with it.

Git is a little bit of a change from svn and make take a little getting used to.

How to set up a git repository and configure for ssh on LInux.

From the command line: (you can check by typing whereis git )
If you don't already have git installed

1) Download git

 wget --no-check-certificate https://github.com/git/git/archive/master.zip

2) unzip git-master
3) cd git-master
4) make
5) make install
6) make sure git is in your path
May want to edit your ~/.bashrc or whatever loginscript you have to edit your path.
Or you can just create a link to it in one of your bin folders : /bin, /usr/local/bin, etc.

To create a repository on the server

1) Make sure git is in your path
Create a new git folder for your projects.
mkdir git
2) cd git
3) create a new project directory
mkdir project1.git
4) cd project1.git
5) git init --bare


To push your code onto the remote repository
1) git remote add origin ssh://username@server_ip/home/pathto/git/project1.git
2) git push


To get the project onto another machine and commit changes
1) git clone ssh://username@server_ip/home/pathto/git/project1.git
2) git remote add origin ssh://username@server_ip/home/pathto/git/project1.git
3) git add whatever_file_you_changed_or_added
4) git commit -m "message here"
5) git push

To update your local copy 
1) git pull origin master
This calls git fetch and merge to get the  latest changes.

Other commands
To see your git commit log :
git log --all


For windows you may want to install the google code project msysgit

Reference links

* http://code.google.com/p/msysgit/
* http://stackoverflow.com/questions/5136381/how-do-i-add-a-remote-git-repository-to-an-ubuntu-server
* http://gitref.org/creating/#init

No comments:

Post a Comment