Home > Git, Solutions Log > Getting Started With Git and GitHub on Mac

Getting Started With Git and GitHub on Mac

I recently got a new Mac and had to go through the process of connecting to GitHub. Here is some notes that I took during this process.

We start our journey at GitHub.com. If you are new to GitHub, you would need to create an account before proceeding. Once you are logged in to GitHub, hit the “Create a New Repo” button on the top right.

1

Enter your new repo information as shown below. I have asked GitHub to create a README file and added MIT License. If you are not sure what license to use, GitHub provides a website to help you with your decision. GitHub also allows you to add a .gitignore file with predefined ignore patterns while creating a repo.

2

Once GitHub creates a repo, you will be redirected to the repo page and you can see the contents of the repo.
3

This concludes our setup on GitHub. The next step is to checkout the repo on to your Mac. Before we do that, check and make sure you have Git instlled on your Mac:
4

Since I have already installed XCode for iOS App development, Git gets installed during that process. If you don’t have Git installed, you can download it from GitHub site.

The next step is to configure Git. Open a Terminal and run the following commands:

 $git config --global user.name "Your Name"
 $git config --global user.email "Your Email Address"
 $git config --global apply.whitespace nowarn

Since we are running on Mac, let’s make sure that .DS_Store folders are ignored globally. To do this, run the following command:

  git config --global.core.excludesfile ~/.global_gitignore
  echo .DS_Store >> ~/.global_gitignore

In the past, I have used SSH Keys to connect Mac to GitHub. Moving forward, I will be using Https instead. One drawback with Https is that it would require us to enter our username and password everytime we talk to GitHub. To fix this, we will use osxkeychain credential helper to cache our username and password. Before you move forward run the following command to ensure that osxkeychain is installed.

git credential-osxkeychain
usage: git credential-osxkeychain 

Now, configure Git to use osxkeychain credential helper:

   $git config --global credentail.helper osxkeychain

We are finally ready to checkout the GitHub repo. Run the following command:

  git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME 

If you have everything setup correctly, Git would create a folder with your repo name and checkout files. You should see a result similar to this:
5

Go to the repo and run git status. You should get message “nothing to commit, working directory clean”.

Let’s modify READEME.md file using your favourate editor. Now running git status shows that we have modified READEME.md.
6

Let’s commit README file by running the following command:

  git commit -am "Updated README"

The final step in this process is to push our changes over to GitHub by running the following command:

  git push origin master

If you are running this for the first time, you will be prompted to enter username and password. Git will cache these and will not prompt you in future. Since, I have this information cached, here is what I get:
7

Go to GitHub.com repo and see that your changes are on the repo:
8

Categories: Git, Solutions Log Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.