How to setup Git and Github on Mac and MacOS (M1 or Intel Chips)

Adam
6 min readMay 4, 2024

--

Photo by Mohammad Rahmani on Unsplash

If you are here, I’m sure you know what Git and Github are, yet you want to setup Git and Github on your local machine, because you just started your coding journey or perhaps, you formatted your MacBook like I did at the time of writing, or maybe you just got a new MacBook (which by the way, congrats!) and you want some help on how to setup Git and Github. Well… you are in the right place.

Photo by Pablo Arroyo on Unsplash

It is simple and easy process, if you follow along, it will only be 03 steps:

Step 01: Download and instal brew.

Copy the following command into your terminal, and if you do not know how to open your terminal: Click COMMAND + SPACE on your keyboard, then type Terminal, and hit return or enter, then you should see something that looks like this pop up:

An image of a terminal, Source: Author himself.

Then copy and paste the following command into the terminal and hit enter or return.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Now let us double check that everything worked and you have the latest version of Git which should be 2.28 or above, by typing the following command into the terminal:

git --version

WARNING! — In case you got something lower than version 2.28, then run the following command in the terminal:

brew doctor

And follow the steps shown in your terminal to fix installation, and also you might want to check your internet connection; However, if you did not get something lower than version 2.28, then you are in a good shape, and it is okay to move to step 02.

Step 02: Connect Git and Github (So they can talk to each other).

You should have a Github account already, and you are following me as well, but if you are not, then go ahead and create a Github account (it is free), and then follow my Github account.

Privacy Warning: If you do not want your email to be available publicly when submitting code to Github, do the following in the email settings of your Github account:

An image showing how make your Github email private, Source: Author himself.

You can find the settings under settings and then emails, or just click here.

Step 02: For real this time.

Now into connecting Git and Github, which you should start by entering the following command into your terminal, and be mindful of adding your name and your email address inside the quotes “”.

git config --global user.name "Write your name here, please"
git config --global user.email "Write_Your@Email.com_Here_please"

Also, Github has changed the branch name from {master} to {main}, which I truly appreciate as a black person myself, so let us update that, by entering the following command into [you guessed it] your terminal:

git config --global init.defaultBranch main

Furthermore; here is a fun one, if you like to see colors in your updates, which makes it easier to read your code, save your code or stage your code, or git status, then enter the following command for colors (keep in mind this command is optional if you want your terminal to be all black and white), but I like some color in my life, so here we go:

git config --global color.ui auto

Now, we will set our default behavior to merging, to make our life down the line easier, by entering the following command into the terminal, which I will not say terminal from this point on, as it should be given at this point, so here we go:

git config --global pull.rebase false

We are at the very end now, let us check everything is working, by entering the following command:

git config --get user.name
git config --get user.email

Which should output your email and name into the terminal console, that you picked at the start.

Now into a crucial step, for us MacOS/MacBook users, and that is to have the Terminal ignore .DS_Store files, which are created automatically inside of MacOS folders or dictionaries, and we do not need to keep track of them anyway, so to ignore them, we enter the following command:

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

Now, we have our local Git, and GitHub setup, so it is time to have them go online in the final step 03.

Step 03: Making our code go to the cloud aka Online.

We start by creating an SSH key, and that is basically a long password to identify your computer from other computers and that means (this password must not be seen by anyone), so enter the following command to generate one:

ssh-keygen -t ed25519

Hit enter, then it will ask for a password, and you do not need one. So just hit return or enter again, and you are good to go.

Now, go to Github and click on settings and then SSH and GPG Keys, or just click here, then click on New SSH Key, which should be a blue button on the top right of your screen at the time of writing.

An image showcasing how New SSH Key button looks like, Source: Author himself.

Now, for the title name it something you can recognize, and in my case I named it, MacBookPro_16_M3. Now go back to your Terminal and enter the following command:

cat ~/.ssh/id_ed25519.pub

Copy the key you see which should start with ssh-ed12345 and end with your computer name, so highlight it all and copy it and then paste it inside of the Key section in your Github.

An image showcasing how the page of adding a new SSH Key looks like, Source: Author himself.

Make sure that the Key type is set to Authentication Key.

An image showcasing what type of Key type you should have for your SSH Key, Source: Author himself.

And WE ARE DONE!

To make sure everything is working, just run the following command:

ssh -T git@github.com
# Attempts to send a ssh signal to GitHub

It will show you the public key fingerprint of Github, if it does match the public key of Github, then type: yes and hit return or enter. Which according to Github website, you should get something along the following message:

> Hi Your_User_Name_Is_Here! You've successfully authenticated, but GitHub does not
> provide shell access.

And if you see this message, then you are golden, and good to go. Now, you can now push from your local computer machine to Github with no issues!

Do not forget to clap for me, as that would make me happy, and say Hello in the comments, or ask any questions you might have!
And with that, have a wonderful day : )

--

--