Git is a popular distributed version control system that allows teams to collaboratively develop software. However, it is beneficial to have a central remote repository from where you can download and upload code. In this article, we will look at how to create remote Git repository.
How To Create Remote Git Repository
If you already have a remote repository and want to create a local copy of it, then use the git clone command to clone the remote repository. Here are the steps to clone a remote git repository.
Here are the steps to create remote git repository from a local one. There are two parts to it. First you need to create an empty repository on remote server. Then you need to push the files from your local repository to the remote one.
Also read: How to Install Git in Ubuntu
On Remote Server
Run the following commands on your remote server to create a bare repository. If your repository is on cloud services like GitHub or Bitbucket, they have a step by step wizard to help you create the remote repository. Please note its URL. We will need it later. Otherwise, follow these steps.
1. Create Repository Folder
Open terminal and run the following commands to create an empty folder and navigate to it.
$ sudo mkdir my_repo $ cd my_repo
2. Create bare repository
Create an emoty repository
$ sudo git init
Bonus Read : How to Enable Keep Alive in NGINX
On Local Machine
Open terminal and run the following commands to push files from local repository to the empty remote one.
1. Navigate to local repository
Go to the folder whose files you want to push to your remote repository.
$ cd /path/to/local_repo
2. Create git repository
Run the following command to create a local git repository.
$ sudo git init
Also read : How to Redirect 403 to 404 in Apache
3. Add Remote Origin
Add remote origin to your repository. Note the URL of your remote repository (e.g myserver/my_repo) when you created the remote repository.
$ sudo git remote add origin ssh://myserver/my_repo
4. Commit files into local repository
Commit files from local repository.
$ sudo git add . $ sudo git commit -m "Initial commit"
Also read: How to Install Pip in Linux
5. Push files to remote repository
Push local files to remote repository
$ sudo git push -u origin master
That’s it. Your local repository is synced with your remote repository. However, instead of pushing a local repository to a remote one, it is advisable that you clone a remote repository to your local machine before you start working on it.
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.