Version Control 449
$ git pull
before push to ensure that you have the latest version before pushing. Now you can go to
github.com and see the history of the repository in github.com.
B.3 Adding Files and Directories
You can add files and directories by using the git add command. The following com-
mands add a file (called prog1.c) to the repository and push it to github.com.
$ git add prog1.c
$ git commit -m ”add a program” prog1.c
$ git push
B.4 Revising a Program
Version control is designed to keep track of changes. Try adding two lines to prog1.c
and then type the following commands:
$ git commit -m ”added two lines” prog1.c
$ git push
Now remove some lines and type the following commands:
$ git commit -m ”changed some lines” prog1.c
$ git push
The history of changes can be seen at github.com. If a line is added, then a “+” sign
appears in front of the line. If a line is deleted, then a “−” sign appears in front of the
line. Using git, you can keep track of changes line-by-line. It is necessary to take small
steps to build a complex program. A professional programmer adds one function at a time,
makes sure it works, and commits a new version before adding another function. Sometimes,
the functions written earlier require improvement. Perhaps the function no longer works as
expected due to some other changes. If you do not use version control, you are out of luck.
It is difficult to remember what changes have been made. Version control can show which
lines have been changed since the previous commit, and thus saves a lot of time. Version
control is very helpful when you learn a new programming language. You can change your
programs without the fear of losing previously working functions. If you make a mistake,
you can easily roll back to an earlier version. Version control can help only if you commit
often. It is quite reasonable if you commit every hour, or even every few minutes. If you work
in a team, you may need to create a branch so that you can commit incomplete functions
without affecting the other people. You can find many tutorials on the Internet about how
to use git. Spend some time learning git and you can save a lot of time managing your
software projects.