DEV Community

Yunshan Li
Yunshan Li

Posted on

Setting Up Your Own GitHub Remote Repository on a Shared Server

When multiple people share the same server, using Git and GitHub can easily cause conflicts—especially if everyone relies on the same global Git configuration. To avoid accidentally pushing code under someone else’s identity, it’s better to create an isolated Git configuration and GitHub remote repository under your own account.

This method was carefully written by the author, and we believe you'll succeed if you follow each step.

(However, if you’d prefer not to go through the hassle of doing it yourself, you can contact the author for paid (low-cost) assistance:https://m.tb.cn/h.hGwnENW?tk=aJwd49rieFc)

1. Check the Existing Git Configuration

First, verify whether the server already has global Git credentials configured:

git config --global user.name
git config --global user.email
Enter fullscreen mode Exit fullscreen mode

If these commands return non-empty values, someone else has already configured Git globally. You’ll want to preserve that setup while using your own credentials.
For clarity, here’s an example of what this might look like:

2. Generate an SSH Key Specifically for Your Account

Each GitHub account needs its own SSH key pair. To avoid overwriting existing keys, generate a new key with a custom filename:

ssh-keygen
Enter fullscreen mode Exit fullscreen mode


When prompted:

  • Specify a custom key filename, /xxx/.ssh/id_xxx, instead of the default. Modify xxx according to your own case, like
  • You can skip setting a passphrase by press Enter twice.  The output will be like  Record the key path: '/root/.ssh/id_gli.pub' (this is the author's; for your own, please find it in your own Bash output). Then open the corresponding file in the target folder:  This entire string is the key—save it for future use.

3. Add the Public Key to Your GitHub Account

Log in to GitHub and click your profile picture.

Navigate to 'Settings' → 'SSH and GPG keys'.


Click 'New SSH key', paste in your key (id_xxx.pub), and save it.




Now, GitHub will recognize SSH connections from your new key.

4. Create a GitHub Repository for Your Project

Go to GitHub and create a new repository:



5. Use an SSH Config Alias to Isolate Your Identity

To avoid interference with others’ SSH setups, define a custom host alias in your SSH configuration:

nano /xxx/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Replace xxx with the path where .ssh/ is located--the method to find it was mentioned earlier above.

Entered the editing interface for config.

Enter the following configuration information.

# xxx account
Host github-xxx
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_xxx
Enter fullscreen mode Exit fullscreen mode

Customize the xxx field to fit your case. The instructions are as follows:

Note the name following Host--github-xxx--and keep it for future use.
Press Ctrl + O to save, then press Enter to confirm.
Press Ctrl + X to exit.
Test your configuration:

ssh -T git@github-xxx
Enter fullscreen mode Exit fullscreen mode

github-xxx is the name defined after Host.
You should see

Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

6. Link Your Project to GitHub

cd /path/to/project
git init
Enter fullscreen mode Exit fullscreen mode



Configure which files or folders in the directory should be excluded from syncing (you can skip this step if it's not needed).

echo "xxx/xxx" >> .gitignore
Enter fullscreen mode Exit fullscreen mode

For example, I configured the dataset folder to be excluded from synchronization:

Add all files to the staging area (files or folders previously set to be ignored will not be added).

git add .
Enter fullscreen mode Exit fullscreen mode

Commit the contents of the staging area. first commit is the commit message and can be modified freely.

git commit -m "first commit"
Enter fullscreen mode Exit fullscreen mode


Set the branch to match the GitHub repository.

git branch -M main
Enter fullscreen mode Exit fullscreen mode

Go back to the GitHub repository and find the SSH clone URL.

Replace github.com with your custom Host name, then enter the following command in the Bash terminal.

git remote add  origin git@github-xxx:xxx/xxx.git
Enter fullscreen mode Exit fullscreen mode


Push the contents of the server's staging area to the GitHub repository:

git push -u origin main
Enter fullscreen mode Exit fullscreen mode


Go to GitHub, reopen the corresponding repository, and check whether the folder contents have been uploaded.

7. The commands for syncing code in the future

After modifying the code later on, you can sync the updated content to the GitHub repository as a backup. The steps are as follows.
In Bash, set the path to the target folder. Enter the following commands one by one.

git add .
git commit -m "xxx"
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)