Create and Push Your Local Git Repository With Command Line Tool - Hub

What is hub (hub source)?

hub is an extension to command-line git that helps you do everyday GitHub tasks without ever leaving the terminal.

Why do I need hub?

It saved me the trouble to sign into Github, create the repository manually, just so I can clone it and work locally.

Current Workflow

Usually when I start a new Github repository, I’ll sign in and then create the new repository. The repository will then show me instructions on how to clone, HTTPS or SSH. Depending on my setup, I’ll clone and start coding.

My Use Case

I started a small throw-away-project, with a local git repository. A few hours later, I decided that the code might be useful and I wanted to formally push it to a remote source control server like Github.

My dream was to drop to the terminal and git -u origin master, that should create and push my local repository to my Github account…of course it is not that simple :)

I searched for a github cli tool and hub came up.
It runs on macOS, Linux, Windows and a few others.

After I installed it, these are the steps I followed to create and push my local repository:

  1. Open terminal and navigate to source code.
  2. Enter: hub create

hub requested my github username.
hub requested my github password.
hub requested my Two-factor authentication code.

After the hub create command, I had a repository in Github…magic :)

  1. git push -u origin master (yes, my dream line becomes a reality)

I also received a Github email notification: [GitHub] A personal access token has been added to your account

Conclusion

Although I only used the create command, I would encourage you to check out the hub manual for more interesting commands.

These two commands are the magic:

hub create
git push -u origin master

Use it…don’t use it :)