Installing Git on MacOS
Before you start using Git, you have to make it available on your computer. Even if it’s already installed, it’s probably a good idea to update to the latest version.
There are several ways to install Git on a Mac:
-
The easiest is probably to install the Xcode Command Line Tools. On Mavericks (10.9) or above you can do this simply by trying to run
git
from the Terminal the very first time.git --version
If you don’t have it installed already, it will prompt you to install it.
- Otherwise you can also install it via a binary installer. A macOS Git installer is maintained and available for download at the Git website, at git-scm.com/download/mac
- You can also install it as part of the GitHub for macOS install. Their GUI Git tool has an option to install command line tools as well. You can download that tool from the GitHub for macOS website, at desktop.github.com
Create a GitHub account
Once you’ve done that, create a GitHub account here. (Accounts are free for public repositories, but there’s a charge for private repositories.)
Create a local git repository
When creating a new project on your local machine using git, you’ll first create a new repository (repo).
To begin, open up a terminal and move to where you want to place the project on your local machine:
cd Desktop
mkdir Matebook-X-Pro-2018
cd Matebook-X-Pro-2018
To initialize a git repository in the root of the folder, run the git init
command:
git init
Add a new file to the repository
touch Readme.md
Once you’ve added or modified files in a folder containing a git repo, git will notice that changes have been made inside the repo.
But, git won’t officially keep track of the file unless you explicitly tell it to.
After creating the new file, you can use the git status
command to see which files git knows exist.
git status
To add a file to a commit, you first need to add it to the staging environment. To do this, you can use the git add <filename>
command.
Now add a file to the staging environment using the git add
command.
git add Readme.md
If you rerun the git status
command, you’ll see that git has added the file to the staging environment.
Create a commit
It’s time to create your first commit!
Run the command git commit -m "Your message about the commit"
git commit -m "Initial commit"
The message at the end of the commit should be something related to what the commit contains - maybe it’s a new feature, maybe it’s a bug fix.
Create a new repository on GitHub
- To create a new repo on GitHub, log in and go to the GitHub home page.
- You should see a green ‘+ New repository’ or ‘New’ button.
- After clicking the button, GitHub will ask you to name your repo and provide a brief description.
- When you’re done filling out the information, press the ‘Create repository’ button to make your new repo.
- GitHub will ask if you want to create a new repo from scratch or if you want to add a repo you have created locally. In this case, since we’ve already created
a new repo locally, we want to push that onto GitHub so follow the ‘…or push an existing repository from the command line’ section:
git remote add origin https://github.com/profzei/Matebook-X-Pro-2018.git git push -u origin master
For a more advanced use, please refer to GitHub for Beginners