Tuesday, March 19, 2024
HomeDevOpsHow to create and add GIT remote repository

How to create and add GIT remote repository

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

# ll

git list

Access Repository:

Now you can make a clone of this repository from clients system using following command.

# git clone git@remote.example.com: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 git@remote.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  git@remote.example.com:project/foxutech.git (fetch)

origin  git@remote.example.com:project/foxutech.git (push)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments