In this blog, we will setup git repository in Ubuntu VPS. We are going to follow these steps:
- Create a git user in Ubuntu server
- Setup authentication for a developer
- Append developer SSH public key in .ssh/authorized_keys file
- Create a empty git repository
- Clone a empty git repository in local system
- Add sample file
- Push latest change to the git repository
- View git log
It will ask you to enter password, type password and press enter key.
We have to install git. Before installation we need to check git is already installed or not.
We can see, git is already installed in Ubuntu 20.04 server. So no need to install.
The command "sudo adduser git" will create a new git user and a new git group. It will ask you to type password for git user, type password and press enter. Again retype password then press ente. For other values press enter, ifyou don't want to change.
sudo adduser git
We have successfully created the git user and group.
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
I will add my SSH public keys to the authozized_keys file.
Make sure you are in /home/git/.ssh folder.
It will open vi editor, press "i" to insert then paste the SSH public key.
Save and exit vi editor.
In this example, i am creating git repository inside /home/git/git_repositories/ folder. You can create git repository directly in /home/git/ directory also, but i would not recommend to do that. So creating git_repositories directory.
git init --bare
We have created the git repository in Ubuntu VPS. Now we have to clone in my local system.
I want to clone repository in G:/projects/git-repos in this directory. You can clone git repository according to your project directory.
You have to use git clone command to clone the git repository. You have to use your server IP and path of git repository.
git clone git@YOUR-SERVRE-IP:/PATH-OF-GIT-REPOSITORY/
git clone firstname.lastname@example.org:/home/git/git_repositories/project1.git/
We have successfully cloned the git repository in my local system. We can see in window explorer also.
Let us add one sample file. I have added test.txt file...
Open command prompt in you local system. Go to project folder and run following commands.
git add --all
git commit -m "Added test.txt file by nutan"
git push origin master
We can see without any error, we have pushed latest chanes to the git repository. Now we will check git log or status in server and local system.
Connect to the server, go to the git repository directory and view git log.
It is showing latest commit log.