For now we install and configured GIT server locally and did all required changes. Now will see, how to add remote git repository in our local project directory? For Example, you have been working on some project long term, but still you didn’t add to git. Before add the project to the GIT, we need to create a GIT repository. Here will see how will create Remote repository and add a local folder to remote repo.
Create System User:
First create a system user, which will be used to connect repository on server from client systems.
# useradd git
Create Bare Repository:
Let’s create GIT bare repository for developers to access remotely. Here will create git repo (foxutech.git) user projects folder (project). Make sure repo name ends with .git
# mkdir project# cd project # mkdir foxutech.git# cd foxutech.git
“init” is using for initialize the repository. –bare for create a bare repository.
# git –bare init
Initialized empty Git repository in /root/project/foxutech.git/
If you list files inside repository you will not find directory named .git due to bare repository, You will see their many files like below
Now you can make a clone of this repository from clients system using following command.
# git clone firstname.lastname@example.org:project/foxutech.git
Add Remote Repository
Now navigate to your project directory and use git remote add command to connect local directory to remote repository.
# cd /devlop/emp03/foxutech
# git remote add origin email@example.com:project/foxutech.git
Check Remote URL
To check remote url in local copy of code use following command. In results you will see two urls one for fetch and one for push operations.
# git remote -v
origin firstname.lastname@example.org:project/foxutech.git (fetch)
origin email@example.com:project/foxutech.git (push)