You will gather the "clone url" from the website and then use the following command.
git clone <clone url>
This will create a new folder containing the repository. The remote will already be connected, and the main branch will already be tracking the remote branch, which means you can simply use git push
and git pull
There are two approaches:
- Create the repo first on the website
- Create the repo first locally
If you choose option 1, you will do the same thing as using an existing repo, you will use git clone
, so follow the instructions above.
However, if you choose option 2:
You initialize the git repo in a new empty folder and optionally tell it what
you want the default branch name to be (often main
)
git init -b <main branch name>
Then create a repository on the website, and grab the "clone url". Be sure to not initialize any files in the repo (like a README.md)
Then you will want to connect your local repo to the remote one, but adding a
remote
, specifying the name (by convention this is usually origin
) and the
clone url.
git remote add origin <clone url>
Then you'll want to make sure you've made a few commits (other wise git will not be able to push anything)
Then you can push, but you must specify the remote to push to. If you add -u
or --set-upstream
it will set up your local repo to "track" the remote one,
allowing you to use git push
and git pull
without specifying the remote.
For example: to push to a remote named origin
with a branch named main
:
git push -u origin main
As you can see, this option takes way more steps. For this reason, I recommend just starting your repo on the remote website, instead of using
git init