Git is a version control system. It allows us, as programmers, to add incremental changes in our code to a repository without losing the history of what we have done. There's a lot of really cool stuff that git lets you do!
Getting Started
I use the terminal for all of my git commands, but using a GUI is fine too, if that makes things easier. The GUI is invoking these same commands that we'll cover.
I also use a Mac for all of my development work, and all of my friends do too. In fact, the place I work won't even let developers use Windows computers for development work! Everyone has to use a Mac or Linux. Macs are great for development work because they have whats called a "terminal".
The terminal is whats known as a "command line interface" and lets you do a lot of powerful things. You can run git there, as well as your server and just about anything else you need to do.
To find the terminal on your iMac, press CMD SPACE on your keyboard to bring up spotlight search, and then type "terminal". Then use the cd command to put yourself in the directory where your source code is. For example, on my computer I would type cd ~/Documents/source-code/my-project.
Another tool you'll want when writing code is a really good editor - I use Atom, which is maintained by GitHub, so it has lots of great git integration built right in. I wrote this cheat sheet with Atom!
Atom also has a large community of developers like you and me that write packages for the editor that allow it to do even more stuff, like test your code for you and code-hint for just about every language out there.
Git Commands You'll Use All the Time
git commit
Stages any changes you've made. When you are happy with a new feature you've added, just type git commit /path/to/file/name. If you want to commit more than one file, you can just add a space between the paths to the files like this: git commit /path/to/file1 /path/to/file2. If you want to commit all the files you've changed, type git commit -a. In the terminal, commands can take arguments just like functions in Python can, and they always start with a dash.
git add
When you've created a new file, you'll need to tell git about it. Just type git add /path/to/file/name to do so. You can also leave off the name of the file, and git will add everything new in that directory.
git status
This will tell you everything that has changed since your last commit. New files that git isn't tracking, changed files, deleted files, etc.
git diff
diff is short for "difference" and will show you all of the things in your files that have been changed since your last commit. Additions are marked with a plus symbol and things that have been removed with a minus symbol. You can also just see the changes in a specfic file by typing "git diff /path/to/file/name".
git push
When you are ready to send your new code up to the repository host, just type "git push". Sometimes you will have to specify the branch you are working on, like so: "git push origin master" where "master" is the branch you are pushing to.
git pull
If you have a friend working with you on your project (or you need to get your code onto another computer) and they have pushed changes, you can grab the updates with git pull. For example, if you and I were working on a branch together, I could type git pull origin dylans-branch to merge your updates with what I have.
Really Useful Git Commands
You don't ever have to use any of these git commands, but they do some really cool stuff and make writing software a lot easier.
git log
This shows you a list of all the changes that have been made, including the ones made by other people!
git branch
Branches in git are just new copies of your code. You can create a new branch from your master branch and do whatever you like without worrying that you'll mess anything up. At my job, we use branches all the time to work on new features and fix bugs. Running git branch will show you all of the branches your local git knows about. If you don't see a branch, you can run git fetch to grab any branches from your remote.
git checkout
Checkout lets you move into a new branch. For example, if I were working on a bug fix I would type git checkout BUG-4123 where BUG-4123 is the name of the branch and corresponds to the name of a bug ticket.
git reset
Let's say you've really screwed something up and your branch is in an awful state and you can't get it back to the way it was. If you type git reset --hard, all the changes you've made since your last commit will be undone. I do this way more than I will readily admit.
git merge
Merge lets you take the changes from one branch and put them in another. This is really useful for when you've added a new feature in a branch, and want to put that feature in master. To merge your code, just checkout the branch you are merging to and type git merge BRANCH-NAME.
Sometimes there will be conflicts - these are the bane of all software developers. Conflicts mean that git wasn't able to resolve the merge on its own, and you'll have to do it by hand. A conflicted merge will leave lots of characters like >>> in your source telling you what git was confused about. This doesn't happen very often, so don't worry about conflicts too much. Atom has a great tool to help resolve merge conflicts.
Misc
I want to delete a file from my repository.
Just delete the file locally, commit the change and push!
I want to delete a repository entirely.
Go to github.com, go to the repo you'd like to delete, go to settings and scroll all the way down to the DANGER ZONE to access deletion.