Source Information
Reference: “How to install Git on Mac” (Atlassian)
Publication Date: October 12, 2023
URL: https://www.atlassian.com/git/tutorials/install-git
1 Open Terminal
First, open the “Terminal” app from your Mac’s Launchpad. You can also find it in Finder under “Applications” → “Utilities” folder.
Terminal is a tool for controlling your computer by typing commands. It’s frequently used in programming and development, so this is a good opportunity to get familiar with it.
2 Check if Git is Already Installed
Recent versions of macOS might have Git pre-installed. Let’s check first.
If Git is already installed, you’ll see something like “git version 2.xx.x”. If that’s the case, you can skip to step 4.
3 Install Git
If the version information wasn’t displayed, you need to install Git.
Method 1: Use Xcode Command Line Tools
Enter this command to install Xcode Command Line Tools (a basic set of tools necessary for development), which includes Git.
When the installation begins, a popup will appear. Click “Install”, agree to the terms of use, and complete the installation.
Information
The installation may take several minutes. An internet connection is required.
Method 2: Use Homebrew (Optional)
If you already have Homebrew installed, you can also use this method.
4 Create a GitHub Account
To connect Git with GitHub, you first need a GitHub account.
Visit the GitHub official website, click “Sign up”, and enter the required information to create an account.
Tip
GitHub accounts are free to create and allow you to join many open source projects and communities. You can also create repositories to store and share your own code.
5 Configure Git with Your GitHub Information
To connect Git with GitHub, you need to register your information in Git first.
These commands set the information that identifies who made the changes when you record changes (commit) using Git.
6 Create SSH Keys and Connect with GitHub
To securely communicate with GitHub, we recommend creating SSH keys and linking them. This allows you to communicate with GitHub without entering a password each time.
Why Are SSH Keys Necessary?
Enhanced Security: SSH keys use encrypted authentication, which is much safer than password authentication. They provide very strong protection against brute force attacks.
Improved Convenience: Once set up, you won’t need to enter your password every time, allowing for smoother GitHub operations.
Foundation for Automation: When using CI/CD pipelines and other automation tools in the future, SSH key authentication is often required.
Refined Access Control: If you work with multiple devices, you can set different SSH keys for each device, allowing for access restrictions to specific devices if needed.
Creating SSH Keys
After entering the command, you’ll be asked where to save the key and whether to set a passphrase. It’s generally fine to go with the defaults (press Enter).
Where SSH Keys Are Stored
By default, SSH keys are stored in the following locations:
- Private Key:
~/.ssh/id_ed25519
- Public Key:
~/.ssh/id_ed25519.pub
Here, ~
represents your home directory, which is typically /Users/your_username/
. Never share your private key with anyone. Only the public key (.pub file) should be registered with GitHub.
Copy the Created SSH Public Key
When you run this command, the public key will be displayed in the terminal. Copy the entire string (starting with “ssh-ed25519” and ending with your email address).
About the Email Address in the Public Key
The email address you specified when creating the SSH key is included at the end of the public key file. This email address is primarily for key identification and is not directly used for authentication on GitHub.
When pasting into GitHub, copy and paste the entire public key string (including the email address). If you remove or change the email address part, the authentication may not function properly.
Register the SSH Public Key on GitHub
Go to the GitHub SSH settings page (while logged into GitHub).
- Click the “New SSH key” button
- Enter any name in the Title field (e.g., “My Mac”)
- Paste the public key you copied earlier into the Key field
- Click the “Add SSH key” button
Connection Test
To verify that the setup was completed correctly, run the following command:
If you see a message like “Hi username! You’ve successfully authenticated…”, it was successful.
About First-Time Connection Warning
When connecting to GitHub for the first time, you’ll see a warning message like this:
This is a normal warning to verify that the server you’re connecting to is actually GitHub.
How to verify the fingerprint:
- Check the displayed fingerprint against GitHub’s official SSH key fingerprints
- If the fingerprint matches, type “yes” to continue the connection
This verification is only necessary during the first connection. After approval, the fingerprint will be saved in your ~/.ssh/known_hosts
file and won’t be displayed in future connections.
7 Learn Basic Git Commands
Now that your Git setup is complete, let’s learn some basic commands.
- git clone [URL] – Copy a GitHub repository to your local machine
- git status – Check the current status of changes
- git add [filename] – Add changes to the staging area
- git commit -m “message” – Record changes
- git push – Upload local changes to GitHub
- git pull – Import the latest changes from GitHub to your local machine
Caution
After creating a repository on GitHub, for the first push, you need to specify the branch like git push -u origin main
.
Why Use Git and Its Benefits
Git is not just a version control tool; it has become indispensable in modern software development. Here are some reasons why:
1. Complete Record of Change History
Git records all changes to a project chronologically. It’s clear who changed what and when, making it easier to track down the cause when problems occur.
2. Efficient Collaboration with Multiple People
Multiple people can work on the same project simultaneously, and conflicts in changes are automatically detected and managed. This makes team development smoother.
Be sure to check out how to build a self-managed GitHub environment for companies!
3. Safe Development of Experimental Features
Using the branch feature, you can try new features without affecting the main development line. If it doesn’t work out, you can easily revert back.
4. Backup and Remote Access
By using remote repositories like GitHub, your code is automatically backed up and can be accessed from anywhere.
Summary
In this article, we explained how to install Git on a Mac and connect it with GitHub. Even if you’re not familiar with the command line, you can easily set it up by following these step-by-step instructions.
Once you master the basics of Git, your programming and team development workflow will significantly improve. Take this opportunity to master Git/GitHub and set up an efficient development environment!
Related Information
Check out Must-see for Mac users! A collection of handy keyboard shortcuts that will boost your work efficiency to further improve your development efficiency!
Leave a Reply