Git Basics
5.6. Git Basics#
Version control is a good idea for any software project. For your work in this class, it will be required. The development environment will periodically wipe your directory, so if you haven’t pushed your changes to a remote repository, you will lose all progress. We recommend committing and pushing your code often to avoid losing your work.
The most common repository control system today is git
and at least int he BU version of this course you will be using github classrooms, which uses the version of git
hosted on github
. Different assignments come from templated repositories that are automatically available to you when you start an assignment.
The power of git is that it maintains a database of all the changes made to a repository. Developers working on their own version of a repository can share changes, along with all the history of how that change was made, with each other. In the very simple environment for this course, there are just two repositories at a time, the one you are working on in the container we provide you, and the one hosted on github.
Whenever you start working, you will need to use git clone <repo>
to make a copy of your repo from github locally. Every time you make a change you can type git status
to tell you the files modified. When you have gotten to a reasonable point in the development, where it is worth recording that in the history of changes, you should use git add <files>
to stage a set of files for commit, and then git commit -m "a message"
to identify the change you have made. Often you will want to have separate messages for different groups of files, so this combination lets you groups changes together in your history. At this point, all the changes are just in the repository on the machine where you are working, and if that machine fails, you will lose everything you have done. You should type git push
to push the changes from your local system to the repository hosted by github. If you take a break, and come back to work, you will want to type git log
to see the history of where you are.
What we have discussed only gives you the basics to work on the projects from our course. Git is increadibly powerful, enabling groups of programmers to share and collaborate on projects. While that would be cheating in this course, in the real world the power of sharing is the real value of git. We would encourage you to explore the rich functionality of git, and if you want to contribute to open source, you will need to learn how to use git to fork or branch repositories, make changes, issue pull requests, …