REMOTE SERVER
1) Prerequisites
The first and foremost thing to think before begin is the server which should be running and accessible from your development computer. I prefer Ubuntu-Server which makes the tasks easy as compared to windows.
If git is not installed, please install it.
sudo apt install git-core
2) Create user git
sudo useradd git
Create password for git:
passwd git
[Alternative way is to create user certificates so that user can directly connect to the git server without even needing passwords]
3) Create folder to store project repositories
Now, I define a folder where I want all git based projects. For that, I have created a folder /opt/git where all project repositories are stored.
su git
mkdir /opt/git
Important: change the owner of /opt/git to git, if this folder was created by other users.
sudo chown -R git:git /opt/git
4) Create repository
su git
cd /opt/git
sudo mkdir project.git
cd project.git
git init –bare
So far, we have created an empty repository where we can push our changes from our development computers.
Please not that, the location of this git repository is represented by:
git@server:/opt/git/project.git
So other users can simply clone this project using
clone git@server:/opt/git/project.git
LOCAL REPOSITORY
For any git project, git prepares local repository where it stores project commits. We can even compare changes, restore to previous versions. Everything we can do even without needing remote server. A developer can manage all changes locally even without letting other developers notice. The remote push server mentioned above is need to push your changes when everything from your side is ready and other developers can implement it.
This section focuses on how can we prepare git client so that we can go on developing.
1) Simple Method:
This is simple method:
cd /home/krishna/workspace
git clone git@server:/opt/git/project.git
It creates an empty project with git repositories prepared. Now we can carry out any changes in this project(create a new file), we can commit it, and then push it to our own server prepared above.
2) Lengthy Method:
This method is a bit lengthy, in case some people interested, they are free to do. We create the repository by ourselves and add remote server to push.
cd /home/krishna/workspace/project
git init
git add .
git commit -m “first commit” .
So far so good, everything is done locally.
Now we define the remote server
git remote add origin git@server:/opt/git/project.git
git push origin master
More Tasks:
1) Disable git to access remote shell
We have a new git user created, and this users can also login to shells to access the remote computer which is undesirable. So, we now enable git use only push and pull using ssh connection which is obtained for enabling git-shell to the git user.
a) Add git-shell in /etc/shells
cat /etc/shells
If git-shell does not exist here, we have to insert git-shell location here
which git-shell
copy this location to the end of /etc/shells. The file should look something like this:
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/tmux
/usr/bin/screen
/usr/bin/git-shell
2) Enable password-less login for git users
It is not always appropriate to provide password to authenticate to git remote server, so we create certificates for users and the specified user can login without need of passwords.
Now lets create a private and a public key for myself.