How to Set Up a New GitHub Repo From Your MacBook

billydharmawan
Mar 30, 2019 · 3 min read

This article walks you through how to use git as your version control tool for your projects. It is assumed that you have already installed git on your local machine. If you have not, this is how you do it via homebrew:

MacBook-Pro:~ bobthedude$ brew install git

Please note that this guide is for beginners.

Why did I write this guide? Because the first time I used git, I started from my local MacBook, not knowing about git clone. So, I thought someone else might do the same thing and this guide would help.

Initialise a Repository From Local MacBook (without git clone)

Again, this is for the case where you already started a local git repo before you create a repo on GitHub ~ you do not use git clone.

MacBook-Pro:~ bobthedude$ mkdir projectdude
MacBook-Pro:~ bobthedude$ cd projectdude
MacBook-Pro:projectdude bobthedude$ git init

After you initialise your local repo above, you remembered that you have not created a repo on GitHub, so you go to github.com and created one called projectdude. Grab the repo url and replace <remote_repo_url> below.

MacBook-Pro:projectdude bobthedude$ git remote add origin <remote_repo_url>

Alternative - You can actually skip step 1, 2, 3 above if you have already created a repository on github.com and do a git clone <remote_repo_url> instead. After this, you can follow the below steps.

Below command will create a local branch named bob-first-branch. You can replace it with whatever name you want for your local branch.

MacBook-Pro:projectdude bobthedude$ git checkout -b bob-first-branch

You can check whether you are on the right branch or not by executing below command.

MacBook-Pro:projectdude bobthedude$ git status
On branch bob-first-branch

Now, you can start adding files, codes, etc. that you need for your project.

You can add multiple files and directories all in one go. Separate them by an empty space. Below examples would add the following:

  • a directory named modules along with the contents in it
  • 2 files, which are app.py and execute.sh
MacBook-Pro:projectdude bobthedude$ git add modules/ app.py execute.sh

Then, commit them. The flag -a indicates you want to commit all the files you added previously, where -m lets you add a commit message/ comment to describe what this commit is about.

MacBook-Pro:projectdude bobthedude$ git commit -am "initial commit"

Two things to specify here:

  • First is your GitHub‘s account email; the email you used to sign up on GitHub.
  • Second is your GitHub‘s user name; this is the name you display when you login to your GitHub.
MacBook-Pro:projectdude bobthedude$ git config --global user.email "bobthedude@something.com"
MacBook-Pro:projectdude bobthedude$ git config --global user.name "bobgit"

This command will create a remote branch on your remote repository so you can create a pull request and later (once happy), merge the branch to your master branch.

The -u flag here indicates you are pushing your local changes in a local branch called bob-first-branch upstream to origin (which you specify in step 3 above).

MacBook-Pro:projectdude bobthedude$ git push -u origin bob-first-branch

That’s it! After this command is executed, there’ll be a link for you to click on that will take you to the page where you can create a pull request.

Happy git-ing. 😃

The Startup

Get smarter at building your thing. Join The Startup’s +793K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

billydharmawan

Written by

A passionate Software Engineer trying to leave a good legacy on earth

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +793K followers.

billydharmawan

Written by

A passionate Software Engineer trying to leave a good legacy on earth

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +793K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store