Disclaimer: setting up a remote repository is OPTIONAL. You can skip this section if you wish.
gh
to create a remote repositoory and link it to a local onegit
can be used exclusively locally and it is completely fine to do so. It can be useful however to also have a remote (online) repository, to easily share it with others and to have a dematerialiased storage.
There are many services that can be used for this purpose. For example:
GitHub
https://github.com
The most popular platform for hosting Git repositories, offering robust collaboration tools, CI/CD, and integrations.
GitLab
https://gitlab.com
Open-source DevOps platform that can be used as a hosted service or self-hosted for full control. It includes CI/CD pipelines and project management tools.
Codeberg
https://codeberg.org
A community-driven, non-profit platform for hosting Git repositories, focused on privacy and open-source principles.
For convenience we will use Github. For this, you need a Github account.
To set up a GitHub account, follow these steps:
Visit https://github.com.
Click the “Sign up” button in the top-right corner of the homepage.
Check your email inbox for a verification email from GitHub. Click the verification link to activate your account.
gh
to create a remote repository linked to your local repositoryTo set up a remote repository on GitHub from a local one using the gh
command-line utility, follow these steps:
gh
(if not already installed)Follow the instructions provided in the welcome page. Further information can be found at the GitHub CLI installation page.
gh
Run the following command to log in to GitHub:
Follow the prompts to authenticate.
Open a terminal and move into your local repository:
Run the following command to create a new repository on GitHub:
This will prompt you with several options:
? What would you like to do? [Use arrows to move, type to filter]
Create a new repository on GitHub from scratch
Create a new repository on GitHub from a template repository
> Push an existing local repository to GitHub
- Select the **last one** ("Push an existing local repository to GitHub").
- Then, press **ENTER** when asked for the path to the local directory (it should be the directory you are in, hence the path is `.`).
- Choose a suitable repository name and yourself as the owner
- Skip the description (or provide a brief one)
- Set the visibility to *public*
- Add a remote and leave the default name **(origin)**
- Finally push the commits.
Example of the creation of a repository called temporary
? What would you like to do? Push an existing local repository to GitHub
? Path to local repository .
? Repository name temporary
? Repository owner FTurci
? Description
? Visibility Public
✓ Created repository FTurci/temporary on GitHub
https://github.com/FTurci/temporary
? Add a remote? Yes
? What should the new remote be called? origin
✓ Added remote https://github.com/FTurci/temporary.git
? Would you like to push commits from the current branch to "origin"? Yes
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 209 bytes | 209.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/FTurci/temporary.git
* [new branch] HEAD -> main
branch 'main' set up to track 'origin/main'.
✓ Pushed commits to https://github.com/FTurci/temporary.git
Check that the remote repository is correctly set up:
That’s it! Your local repository is now linked to a remote repository on GitHub.