Git + GitHub Tutorial: Basics of Working with GitHub on a Mac đŸ’»

This article provides a step-by-step guide of how to create a remote repository on GitHub and how to work with GitHub locally, keeping everything in sync.

11 min readFeb 13, 2024

Ever felt overwhelmed by the thought of using Git and GitHub? You’re not alone. It really does look confusing and cumbersome. But I’m here to help. Because I’ve been there myself. So let’s not drag this out and get it over with once and for all.

In just 15–20 minutes (reading time and following the steps), you will learn how to:

  • ✅ use Git in the macOS Terminal
  • ✅ set up remote repositories on GitHub
  • ✅ and most importantly — connect your local and remote repositories

â˜đŸ» This guide is for anyone who knows the purpose of Git and GitHub but haven’t tried them yet.

I put together this guide from various courses and guides on Git services. I selected the best parts, rtrimmed the fat to tailor it for GitHub and Mac users. So, you learn a lot quickly.

As you read, it’s best to follow along as you read. This way, you’ll understand the material better, set up accounts in the necessary systems, and get hands-on experience with Terminal and GitHub.

Getting Ready to Dive In đŸ€“

You’ll need:

â˜đŸ» Many graphical interfaces exist for Git, including GitHub’s own. You might explore these options later, but we’ll stick with Terminal here for a direct learning experience.

Setting Up Git

If you’re new to Git, start by setting up your user profile by adding your username and email. Open Terminal and run these two commands sequentially (enter your name and email without brackets):

git config --global user.name "Your Name"
git config --global user.email "your_email@whatever.com"

To verify, run these commands to see your entered details:

git config user.name
git config user.email

Keep Terminal open; you’ll need it for the next steps.

Creating a Remote Repository

A remote repository on GitHub is a cloud storage where your project files and their change history are kept. Locally means it’s just a folder on your computer.

People use GitHub repositories for many things:

While the actual work with code and files is done locally — in the project folders on your computer — these folders connect to your cloud repositories on GitHub.

Here’s what you need to do:

  • Create a project on github.com
  • Clone it to your computer

â˜đŸ» You could start differently, but this way is easier for beginners.

It’s smart to make a new repository on GitHub for every project. Next, I’ll explain how to set up a remote repository and a local folder for a test project named ‘hello-world’ and sync them.

Creating and Setting Up

To start a new GitHub repository, click the + sign at the top right corner and choose New repository from the menu:

Creating a new remote repository on GitHub

You’ll then see a page to set up your new repository. Here’s what to do:

  • Name your repository
  • Optionally, give your project a short description
  • Decide if your repository will be Public (anyone can see and contribute) or Private (only people you choose can see it)

â˜đŸ» GitHub offers Public and Private repositories. Public ones are open for everyone to see and contribute to, while Private ones are just for you and anyone you invite.

  • Tick the box to Initialize this repository with a README for an instant overview of your project

â˜đŸ» It’s a good practice to include a README in Public repositories for a quick project summary. The details you enter in the Description field get automatically added to this file, making it visible on your project’s main page.

  • Add a .gitignore file if your project has specific files you want to exclude from the repository (useful for larger projects, but we won’t dive into that here)
  • Include licenses if your project uses licensed materials, like certain fonts
Adding a description and initial setup of the remote repository

With these steps complete, click the green Create repository button to finish.

🎉

Repository Page

On your new repository’s page, find everything you need under the Code tab. This includes your README file, prominently displayed.

Initially, your project includes a README.md file, a single commit marking the creation, and one branch — the primary main branch.

â˜đŸ» For product managers or analysts, the main branch usually suffices. Complex projects or team collaborations might require additional branches, a topic we’ll explore later. Remember to hit Follow for updates.

Project page on GitHub

Project Working Folder

Chances are, you’ve got a projects folder already. If not, it’s time to make one. Next, you’ll use Terminal to access this folder.

â˜đŸ» There’s no need to create the project folder itself; it will be cloned from GitHub.

Early on, navigating files and folders through Finder is intuitive. To quickly access your projects folder in Terminal from Finder, simply right-click on the folder and select New Terminal Tab at Folder.

Quick access to a folder in Terminal from Finder

This action opens a Terminal tab right in your project’s folder.

Cloning a Remote Repository

To manage a project on your local machine and keep it in sync with the remote repository on GitHub, you’ll need to clone it. Here’s how.

  • Navigate to your project’s page on GitHub and click the Code button to copy the repository’s URL
Cloning a GitHub project
  • Open Terminal (the tab you’ve opened via Finder) and execute the following command, replacing “URL” with the actual URL (without brackets) you just copied:
git clone "URL"
Executing the git clone “url” command in Terminal

Once the command finishes, Terminal confirms with a “done” message, and you’ll see the project’s folder, now cloned, in your local projects directory. You’re all set to modify files, add new content, and ensure everything stays updated with the remote repository.

📌 TLDR

To connect a new GitHub project with a folder on your computer, follow these steps:

  • Create a new project (repository) on GitHub and grab its URL
  • Open Terminal and head to your general projects folder (no need to make a specific folder for this project)
  • Clone the GitHub project locally with git clone “URL” (replace “URL” with the actual URL you copied)

â˜đŸ» This approach lets you bring any project from GitHub right onto your local machine.

Synchronizing Local Changes with a Remote Repository on GitHub

Changes to the Project

For a hands-on demonstration of synchronization, let’s make two updates:

  • Modify the README file
  • Insert an image into the project folder

Follow along with these steps to get comfortable with Git.

In the README.md, I’ve inserted “My furst commit” — notice the typo, which we’ll fix later as we explore how to edit files directly on GitHub.

Editing a file in the project folder on the computer

Also, I’ve added an image named project-page.png, a screenshot from this guide, to the project folder.

Adding a file to the local project folder

Git Flow

To keep your local and remote repositories in sync (updating a file and adding an image in this case), you need to add, commit, and finally push these changes.

The key steps are git commit and git push, with git add serving to stage changes.

â˜đŸ» A commit acts like a save point in your project, allowing you to revert back if needed, akin to game saves. These checkpoints are synchronized between your local and remote repositories.

Push applies your committed changes to the remote project.

Now, let’s dive into each step.

Checking Git Status

Work on your project takes place within its local directory. Open this directory in Terminal for direct manipulation. If you’ve navigated away, return to your project’s folder with the command below, replacing “project folder name” with your actual folder name (without brackets):

cd "project folder name"

Remember, using Finder’s right-click menu to open Terminal at your project’s folder streamlines this process.

Git Add and Git Commit Commands

First, ensure you’re in your project’s directory in Terminal, as all modifications occur within this folder. To see what’s changed, run:

git status

📌 A detailed list of Git and GitHub commands will be shared later in this guide.

â˜đŸ» While not essential, git status is a helpful command to familiarize yourself with. It lets you peek at your project’s current state anytime.

Viewing information about changes in the project using the git status command

This command reveals the project’s status. Changes not yet staged for commit are marked in red, giving you a clear view of what’s been altered but not yet committed:

  • On branch master (now it called main instead of master)— signals the branch you’re on

â˜đŸ» Handy for navigating multiple branches.

  • Changes not staged for commit — indicates modifications not yet prepared for a commit (e.g., updated README.md)
  • Untracked files — shows new files added to the folder but not tracked (like project-page.png)
  • no changes added to commit — means there’s nothing ready to be committed just yet

Git will suggest your next steps, hinting at using git add <file>
 to start staging your changes.

git add (Staging Changes)

Use the git add command to stage changes in your project’s folder. For substantial projects, you might stage just one file at a time using its name and extension (without brackets):

git add "file_name.extension"

To stage all modifications together, which is ideal for smaller projects, use:

git add .

Running git status afterward lets you verify that all changes are staged for commit (though this step is optional).

git status output when all changes have been added

git commit (Creating a Commit)

To bundle your changes into a commit with a descriptive message, execute (here, write the comment as in the example — in quotes):

git commit -m "Change README, and add screenshot"
Extended git commit command

â˜đŸ» Commits should encapsulate a cohesive set of changes, like a newly added feature or an update to existing functionality. Describing these changes in your commit message is a best practice for clear project history.

After committing, git status will confirm there are no pending changes, indicating your commit is ready but not yet pushed to the remote repository.

git commit command shows that one commit is not pushed

git push (Pushing Changes)

To upload your local changes to the remote repository, execute git push. To specify the branch you’re pushing to, use:

git push origin main

â˜đŸ» On your first git push, Git will prompt for your GitHub credentials. As a password here, you should use a Personal access token, read here how to make one. Although entering your Personal access token won’t visually alter the screen (no moving cursor or characters), just paste it and press enter. A correct entry will successfully push your changes.

git push origin main command

After pushing, git status will confirm there are no outstanding changes — indicating everything’s been committed.

Your branch is up to date, nothing to commit, working tree clean

Your GitHub project is now current, reflecting all local changes including any new commits, file additions, or README updates.

The Information has been updated on the project page on GitHub

📌 TLDR

To update the remote repository with your local project changes:

  • Open Terminal and go to your project directory
  • Stage your changes with git add .
  • Commit those changes using git commit -m “Your message here”
  • Finally, push your commit with git push origin main

â˜đŸ» Use git status to keep tabs on your project’s current state and what changes are staged or committed.

Updating the Local Repository After Changes to the Project on GitHub

Sometimes, files in your project might be updated directly on GitHub or by other team members. When this happens, you need to bring those changes into your local repository.

Editing Project Files on GitHub

To demonstrate syncing I’ve updated the README file on github.com.

â˜đŸ» Remember, every change made on GitHub counts as a commit. So, when you save your edits, a new commit is instantly created in your project.

Editing files on GitHub is straightforward thanks to its built-in editor:

  1. Open the file to edit and type your changes;
  2. Provide a commit message explaining them;
  3. Hit the save button to commit your changes.
Editing a file and saving a commit on github.com

Once saved, this commit is instantly active, incorporating your changes into the project and your description to the commit.

A commit is added, and the README.md file is updated

GitHub keeps a log of all commits, complete with details. Viewing any commit lets you see the changes made, with deletions in red and additions in green.

Information about the changes in the commit

Pulling Changes to Your Local Repository

To sync your local repository with the latest changes on GitHub, navigate to your project’s folder in Terminal and run:

git pull
The output of the git pull command

Executing this command pulls the latest updates from GitHub, displaying what’s being updated in Terminal. Once git pull completes, your local project files reflect the most current version on GitHub. Check the README in your local folder to confirm these updates.

The README.md file in the project folder on the computer is updated

📌 TLDR

To keep your local project up-to-date after changes on GitHub:

  • Open Terminal, navigate to your project’s folder, and execute git pull

📌 List of Commands for Working in Terminal with Git and GitHub

Setting Up Git

  • git config — global user.name “Your Name” — Set your username (without brackets)
  • git config — global user.email “your_email@whatever.com” — Set your email (without brackets)
  • git config user.name — Check your currently configured username
  • git config user.email — Check your currently configured email

Managing Repositories

  • git clone “URL” — Clone a repository from GitHub to your local machine (URL without brackets)
  • git status — View the status of your local working directory (see what’s changed, added, or ready to commit)
  • git add “file_name.extension” — Stage a specific file for commit (file name without brackets)
  • git add . — Stage all changed files in the directory for commit
  • git commit -m “commit description” — Commit your staged changes with a descriptive message
  • git push origin main — Push your committed changes to the main branch on GitHub
  • git pull — Pull the latest changes from the remote repository to your local directory

And there you have it — a comprehensive guide to getting started with Git and GitHub on your Mac. Don’t hesitate to experiment with new commands, explore additional features on GitHub, and collaborate on projects to enhance your skills. Happy coding!

đŸ‘‰đŸ» Follow me on X (twitter)

For more insights and tips on navigating technical topics in simple language, make sure to follow my X (twitter) or LinkedIn. I regularly share knowledge aimed at demystifying tech for non-technical specialists. See you there!

đŸ‘œ

--

--

Anton Bykov
Anton Bykov

Responses (2)