Linking Local and Remote Repositories
Tuesday, September 2nd, 2025
Quick memo to self as I always forget how to connect a remote repository to an existing local one.
The scenario here is an idea has been worked on locally and git is being used to track progress. The project eventually reaches the point where it might be useful to others. The most obvious way to do this is to use GitHub to publish the project.
Local Repository
Creating a local repository is usually performed using a git init command:
git init .
which will result in output like:
Initialized empty Git repository in /Users/username/GitHub/ProjectName/.git/
From here on in it is a case of following the normal development methodology for the project in question.
Create the Remote Repository
Next up to create the remote repository:
- Login to GitHub using your credentials
- Click on the Repositories link
- Click on the New button
- Fill in the details for the repository
At this point we have a new remote repository.
Linking the Local and Remote Repositories
At this point we should have two repositories:
- Local repository with some work and the associated history
- Remote repository with a small amount of content (readme, maybe licence etc.)
The two can be linked as follows:
git remote add origin https://github.com/NevynUK/TemporaryTest.git git branch -M main git push -u origin main
Conclusion
The two repositories should now be linked and the local content should have been synchronised with the remote repository.
No revelation here but something that is often forgotten.