Git is a distributed version control system. It's great strength is that it helps us a) keep track of old versions of our work, and b) helps us to collaborate. That is enough for the hand-wavey explanation. It is a big, broad overgeneralization, but it will do for now.
While git is completely freestanding, GitHub has the lion's share of the mindshare, and many people store a copy of their repository there (you don't need a remote site for your repository, but it facilitates collaboration). We will be using GitHub Classrooms for this class, so you need an account there.
The next thing you need is a git client. If you are going to us git a lot, I suggest learning the command line client (which is installed on the Linux machines).
However, a GUI tool also has its uses. I currently recommend GitKraken. It has everything you need already included, so you can be up and running with a single download. SourceTree is another option that works well. I find GitKraken to be a little more intuitive, but your milage may vary.
If you are running GitKraken, you should set up your GitHub authentication. Go to 'Preferences' -> 'Authentication' -> GitHub.com and follow the directions to link your account.
When you add this, GitHub will approve GitKraken as an authorized application for OAuth authentication. Unfortunately (as we found in class), this does not authorize GitKraken for access to private repositories in Organizations (i.e., our class) you have access to. So, we have to do this manually.
Middlebury-CS465
). Click the Grant button to give GitKraken access to the class.For every project, you will create a new repository. This holds all of files associated with your project. As you make changes, you will commit the changes, and the repository will remember these all separately, so you can always return to previous versions.
Git is distributed version control in that there can be lots of different copies of your repository. For us, that will be, at minimum, the copy on your machine where you are working, and the copy living on the GitHub servers.
Repositories can be made locally on the command line by typing git init
in a directory you want to become a repository. Obviously, GUI tools also have the ability to create repositories. By in large, however, you will create the repository on GitHub. For the assignments based on GitHub, this will happen automatically.
Making copies of repositories is called cloning. For repositories created on GitHub, we will need to do this to get a local copy we can work on.
There is a big green button on the right side of GitHub repository pages called 'Clone or download' -- clicking it will provide you with the URL of your repository (don't just download the zip file).
On the command line you can type git clone *URL*
.
In GitKracken, you will find a 'Clone Repo' option in the 'File' menu. You will find a GitHub.com tab where you can enter the details for the repository to clone.
Saving changes into your repository is a two step process.
First you need to stage the changes. On the command line, we use git add \<file\>
, where the file is the one containing the changes.
In GitKraken, you will see the changed files listed on the right under 'Unstaged Files'. You can stage them all at once 'Stage All Files', or individually.
Once files are staged, they need to be committed. On the command line, we use git commit -m "Some message"
. The message should be a description of what changed with this commit.
In GitKraken, there is a handy message field at the bottom on the right hand side, and a big Commit button underneath it.
Committing your changes only stores those in your local repository. If you are going to share those changes (which you will want to so i can see them), you need to push the changes back to the repository on GitHub.
On the command line this is done with git push
.
In GitKraken, there is a push button at the top of the window.
This is just barely enough to get you to a point where you can use git for this class. There is a lot more to know about git. Here are some more places to go for more information:
git - the simple guide GitKraken documentation git documentation