Make sure that following tools are installed on your Mac
- Apple’s Developer Tools
- MacPorts Package Manager
If you don’t know what are these then don’t worry. Follow this beginner tutorial to install Apple’s Developer Tools and MacPorts.
In step #1 we installed Apple’s Developer Tools. It installs a set of tools for development and along with other tools it also install git. In the terminal, run
and it will return something like
git version 2.39.3 (Apple Git-145)
We will use this git. If you want to use the latest version then you can install it using
sudo port install git
git config --global user.name "username"
git config --global user.email "email@example.com"
firstname.lastname@example.org with your’s.
Now it’s time to learn version control using git
Create a GitHub account to host your code on cloud and share it other developers.
You need to connect your git to GitHub. You can either connect over HTTPS os SSH. For beginner I would recommend to connect over SSH. Follow the following docs:
Open your terminal and run the command below after replacing
"email@example.com" with your email address you used to create your GitHub account in step #3
ssh-keygen -t ed25519 -C "firstname.lastname@example.org"
This will prompt you for a file to save keys (press enter for default file location) and then asks for password (choose a password or press enter for empty password)
Generating public/private ed25519 key pair.
Enter file in which to save the key (/xxxx/xxxx/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
This will create a pair of private and public keys
Once these keys are generated successfully, run the ssh-agent in the background
eval "$(ssh-agent -s)"
~./ssh/config exists, else create one
~./ssh/config in your favorite text editor and add these lines
# Uncomment below line if you choose a password to generate keys
# UseKeychain yes
ssh-add -D # Will delete all identities added previously from the ssh agent
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Check the added key with
- Copy the generated public SSH key on clipboard
pbcopy < ~/.ssh/id_ed25519.pub
Go to your GitHub account and click on your the avatar on top right corner and then click on Settings
On the left sidebar, click on SSH and GPG keys and then click on New SSH Key
Add some title if you wish (like “My MacBook’s SSH Key”)
In Key Type section, select Authentication Key
Paste the public key in the Key section.
ssh -T email@example.com
If you setup your git and GitHub account correctly then the above command should return the below message
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
Create a new repository
demo on GitHub. After creating the repo successfully you will see three options to clone your repo: HTTPS, SSH and GitHub CLI. Choose SSH and copy the remote url.
Open your terminal and clone this repo typing
git clone and then paste your repo remote url.
git clone firstname.lastname@example.org:haccks/demo.git
Now you can go to the
demo directory and start making changes and push it to the GitHub.
Create a local repo named
and perform these actions
git add README.md
git commit -m "First commit"
# Connect your local repo with the remote repo
git remote add origin email@example.com:haccks/demo.git
git branch -M main
git push -u origin main
If you already have a local repo then ignore the first four commands and use the last three only.
We are done here!
If you want to use multiple github accounts on Mac then follow this tutorial: How to use multiple github accounts on Mac?