-
Notifications
You must be signed in to change notification settings - Fork 473
Using Git with Terminal
Git is an essential tool in the developers toolkit. Git stores your files like a stream of snapshots, allowing you and other collaborators to make changes to projects and keep everything in sync. This Guide will cover using Git with Terminal.
The Terminal is much like the finder, but less pretty. There are just a few basic commands needed to navigate around in Terminal. Using Terminal, we often refer to folders as directories. Check out this Terminal Cheat Sheet for Mac for a more complete list of commands.
- Open up terminal, cmd + space "terminal".
-
pwd
Figure out which directory you are currently in by "Printing the Working Directory". -
ls
List the directories and files inside the current directory.-
ls -a
include hidden files in the list of directories and files. This is helpful when trying to find hidden files like.git
or.gitignore
-
-
cd [folder]
Go into the folder. e.g.cd Desktop/Developer
-
cd
This by itself will navigate all the way out to your Home Directory -
cd ..
Back out to the parent directory of the current directory.
-
-
open [file]
Same as "double-clicking" a file or folder in finder.-
open .
Opens the current folder or file in finder or it's default application.
-
-
clear
When you need a fresh Terminal window
Hint If you can't find the path to a file or folder through terminal, search for it using Finder, then drag the file or folder right into your terminal window! If you are trying to change to that directory, you will need to typecd
before dragging in the folder.
Local Git repositories are created and managed locally on your computer.
- Xcode will automatically create a local Git repository for your project if you select, "Create Git repository on... My Mac", when you first create your project. You should Always select this when creating a new Xcode project.
If you already have a project, where a Git repository was not created when you made the project, you can create a local Git repository using terminal.
- Navigate to the Xcode Project folder in Terminal.
git init
Now that your local Git is all setup from the last step, you can update your local Git repository with any changes you make to your project.
- Stage all the changes you made.
git add .
- Check to see what was added.
git status
- Apply the changes to your local Git repository with a message briefly outlining the changes you made.
git commit -m "Here is my commit message"
There are many remote repository options. In this guide we will be using GitHub.