One of Git’s strengths is the ability to configure a repository locally, so you can dive right into an idea regardless of whether or not you have a reliable (and secure) internet connection.
Once you’re ready to share your code, one of the easiest and cheapest ways to do so is to import this local repository to GitHub. Here’s how:
- Log into your GitHub account. If you don’t already have one, sign up for free.
- Click the “+” in the upper-right corner of any page and select “New repository”.
- Enter a name (and optional description) for your repository.
- If you have a paid account and you don’t want your code to be visible to the GitHub community, click private. Otherwise leave public selected.
- Leave Initialize this repository with a README unchecked.
- Click Create repository.
- When the page reloads, copy the repository URL. It will follow this format:
- Open a terminal window and navigate to the directory containing your local repository.
- If you haven’t already initiated a Git repository, do so with this command:
- Set the remote origin for your local repository to point to the repository you just set up on Github:
git remote add origin https://github.com/[username]/[repository-name].git
If it’s a private repository associate your username with the repository in this command to save yourself some typing:
git remote add origin https://[username]@github.com/[username]/[repository-name].git
- Finally, push the contents of your local repository to GitHub:
git push -u origin master
Your project is now on GitHub. In addition, your local and GitHub repositories are now connected and can be kept current to one another with the
pull commands (depending on the direction in which the changes are moving).