Git Tutorial

Adding a Remote

We want to share our work with the world! Let's create a repository on Github.

If You Added a README.md on the Github Website

Git is going to complain because your local repo and the repo on Github (origin) are different. It wants you to pull in the new changes from Github before pushing your new changes.

Deleting a Repo

So you put a git repo where you didn't want one. Maybe you put your whole hard drive under version control. What next?

git keeps all of its files in a .git directory - to delete the repo, we just have to remove that: rm -rf .git. This says remove the git directory and everything inside of it and don't ask me to verify deletes.

Cloning

So you've got your repo created and being hosted on github. What if you want to work on your files on a different computer? You should clone (duplicate) your repository!

Forking

You see some code you'd like to modify for your own purposes - you should fork your own copy!

Branching

What if we want to maintain different versions of our code? Say we want to store a version for required, B, and A functionality. Or maybe we've got a piece of functionality going and we want to add a new feature without breaking existing code. These are use cases for branches!

I'll use the "add a new feature" in my example. Imagine we have our robot navigating the maze using IR sensors. But we want to add a sonar feature to increase accuracy without breaking functionality of our working code.

Ignoring Certain Files

Sometimes there are a bunch of files in your directory that you don't want to place under version control. It's annoying to have git constantly complaining about these files being untracked.

Temporarily Ignoring

Instead of git status, type git status -u no. This will not display status information on untracked files.

Permanently Ignoring

We can specify files we don't want to track in a .gitignore file! For instance, vim creates .swp files when you open files for editing. I don't want those to go under version control. So I can specify that in my .gitignore:

.gitignore contents:

*.swp

Now, git won't notice changes to any .swp files.

Make sure you add your .gitignore file to git and commit it!

Here's a bash command to add all currently untracked files to your .gitignore, if that's what you want to do:

git status --porcelain | grep '^??' | cut -c4- >> .gitignore