Create a git repository and push to GitHub

Last modified on 2020-04-27

Steps to create a local git repository, then push (upload) to GitHub for hosting.

Let’s go!

1. Install git. On Debian/Ubuntu: sudo apt install git.

2. Create a user configuration by running git config. Variables are stored in ~/.gitconfig file. Example …

$ git config --global user.name "Foo Bar"
$ git config --global user.email foo@barnone.com
$ git config --list
user.name=Foo Bar
user.email=foo@barnone.com

3. Turn a project currently not under version control into a git repository by running git init inside the project directory.

4. Add files to be tracked and commit …

$ git add README.md
$ git commit -m 'first commit'

5. Sign-up for a free GitHub account.

6. Setup the account to use SSH keys for data transfer. Login and navigate to Settings->SSH and GPG keys. Click New SSH key and copy/paste in your *.pub key. Test the connection by running ssh -T git@github.com.

7. Create a public repository on GitHub. Select +->New repository, fill in the details, and click Create repository.

8. Import. Quick setup is set to SSH and opt for ... or push an existing repository from the command line. Example …

$ git remote add origin git@github.com:foobar/my-repository-name.git
$ git remote -v
origin  git@github.com:foobar/my-repository-name.git (fetch)
origin  git@github.com:foobar/my-repository-name.git (push)
$ git push -u origin master

Happy hacking!