gitosis is a great way to have a private git server. To install gitosis and perform the basic configurations refer to this guide. gitosis can use ssh access to your remote repositories. Unlike svn (and many other version control systems), git keeps an entire snapshot for your commits instead of a series of diffs. This is great because you can see the entire history of your project locally and develop locally. This comes handy when you do not have access to the internet to push your commits to the remote repository. Moreover, even in the event that the remote repository dies, you can still recover your code using your local database. For this and many other reasons (such as the distributed mirroring and the free github), git is the most popular choice for version control.
Installing gitosis in your remote server
Once you have installed gitosis in your remote server, you must clone gitosis-admin repository to your local machine. You can perform numerous administrative tasks locally via this repository such as adding new projects.
The first time you use git to push something you must specify your name and e-mail address. This can be done as follows.
git config --global user.name "Your Name"
git config --global user.email you@example.com
To add a new repository do as explained here.
Installing gitosis in your remote server
Once you have installed gitosis in your remote server, you must clone gitosis-admin repository to your local machine. You can perform numerous administrative tasks locally via this repository such as adding new projects.
The first time you use git to push something you must specify your name and e-mail address. This can be done as follows.
git config --global user.name "Your Name"
git config --global user.email you@example.com
To add a new repository do as explained here.
- cd gitosis-admin
- git pull This will update your gitosis-admin repository
- If you do not have your gitosis-admin repository, then you must first clone it by
git clone gitosis@server:gitosis-admin.git - Now edit the gitosis.conf file and add your newproject details
[group helloproject]
members = mylogin@myhost
writable = helloproject
Note that the last one is "writable" and not "writeable" - Now commit the changes you made to gitosis-admin repository by,
git commit -am "added the project helloproject"
next push the commit to the local db by git push - Now move to the directory that contains files for your new project "helloproject". Then do git init
- This will initialize the new repository. You can add individual files to track using
git add filename
You cannot add an empty directory to git repository. When you add a file from a directory that directory will be automatically added to the repository. However, if you want to add an empty directory to the repository you can either place a dummy README file in that directory or write a .gitignore file in the directory that you want to add. The .gitignore directory must contain the following two lines.
# Add everything in this direcory
*
# Except for this file.
!.gitignore - Once you have added the files for the newly created helloproject you must commit them.
git commit -am "Initial commit for helloproject" - Now you need to add this new project to your remote repository by
git remote add origin ssh://gitosis@myserver/helloproject.git - You can now push the changes to your remote repository
git push --all - In order to be able to pull back to the same directory (without cloning the pushed project from the remote server) you must edit .git/config file as follows.
[branch "master"]
remote = origin
merge = refs/heads/master - That is it.
Git development cycle (command used frequently)
- You would either add an existing project to git as explained above or will clone a project from the remote repository. To clone do as follows.
git clone gitosis@myserver:helloproject.git - Now you will modify some tracked files and/or add new files to be tracked using
git add filename - Note that there is this concept of staging in git which means you must first "stage" files to be committed and then perform the actual committing. This means you will have to add again any files that you have modified in order for them to get committed. This additional staging step can be skipped by using the -a option during commit.
git commit -am "message" - Commit actually commit things to your local repository. It does not push your changes to your remote server. To push your changes to the server do as follows.
git push - This is the basic (frequent) development cycle. Note that if someone else have pushed before you (i.e. origin has been modified by some other person other than you), then git push will fail. You must first git pull their changes and then check them with your modifications (git fetch will not merge but git pull will try to merge) and then git push again.
Git useful tricks
- Use git status to see what are the changes that are going to be committed in the next commit.
- You can use tags to easily refer (and checkout) important milestones of your project.
To list the current tags do
git tag -l - To create a new tag do as follows
git tag -a v1.0 -m "first version" - To push your tags to the remote server do,
git push origin v1.0 - Now when someone clones this repository that person will also receive the tag v1.0. After cloning a project you can checkout a specific tag as follows.
git checkout v1.0 - If we want to delete the tag see here.
Git hub
- cloning a repository from github
- git clone git://github.com/Bollegala/svdmi.git
- You might not be able to push to the original git directory if you have not set the git url as follows
- git remote set-url origin git@github.com:Bollegala/svdmi.git