Skip to content

Instantly share code, notes, and snippets.

@imsurinder90
Created August 14, 2020 16:20
Show Gist options
  • Save imsurinder90/5aff0455b264c79ebd0c143090c1a556 to your computer and use it in GitHub Desktop.
Save imsurinder90/5aff0455b264c79ebd0c143090c1a556 to your computer and use it in GitHub Desktop.
Guide on how to setup a remote repository on remote server or location in Git
The best practice to share code using Git is to setup a remote repository on some server <ServerA> at a location /usr/git/. We will now create a
repo at this location which will act as a central repo where multiple remote users can get access to the code and even can push/pull the code.
Let's say we have a central server where Git code will present and
2 remote user User A and User B.
Simple steps:
1. Now, go to central server and then create a project folder, type:
user@central_server: mkdir /usr/git/<project name>
2. Remote repositories need to setup as bare repo and such repos just contains version history of code, no actual code is checked out.
Run below command to create bare repo.s
user@central_server: git init --bare /usr/git/<project name>
3. On Remote User A or B, user will clone the repo from central server
remote_userA@mypc1: git clone ssh://username@central_server:/usr/git/<project name>
4. Repo is now cloned and remote users A and B can add new files to this and checkout the code.
By default remote repo is pointed to master using name --origin, you can change it to a different name if you like
5. Let's add a couple of files to this project and checkout on remote server.
remote_userA@mypc1: cd project name
remote_userA@mypc1: git add README.md
remote_userA@mypc1: git add run.py
6. Commit the changes
remote_userA@mypc1: git commit -m "commit message here"
7. Use the below command to push commited changes to master branch on remote server
remote_userA@mypc1: git push origin master
8. Now go to central repo/server, run below command:
user@central_server: git pull
9. Now here you will find files in central server. Type:
user@central_server: git log
Hope it helps!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment