Git: Getting started
The basic idea
Each time a change is made to your project, a snapshot can be made of the current state. This is called a "commit". Every commit is linked to the previous version, making it possible to traverse back in time.
This makes it possible to undo changes anytime. Git also allows to share those changes with developers working on other parts of the software.
Making it all work
Git is developped as a set of command-line tools. On top of these tools, other developers have built nice graphical frontends. Feel free to use whatever tool suites you best:
Git clients for Windows:
Git clients for Linux:
The command prompt
In this tutorial, the Git command prompt is used, but the concepts of the tutorial are easily applied to any graphical Git client. The command prompt is used for a few simple reasons:
- It has the latest features.
- It is universal across all platforms.
- It is mostly used in examples on the web.
- ...and it's not really that difficult to use!
First, You need to introduce yourself to git.
- Tips of Windows users
In the "Git bash" command prompt, you can auto-complete commands and parameters with the TAB key. Press TAB again to see a list of suggestions.
- Enter these commands:
git config --global user.name "Diederik van der Boor" git config --global user.email "vdboor@...."
And optionally, configure some settings:
- Useful settings:
git config --global color.ui auto
# colorize all messagesgit config --global alias.st status
# alias "git status" as "git st"git config --global core.editor kwrite
# e.g. you dislike VIM as editor
You can also edit these settings in the
The basic commands
As quick reference, here are the basic commands to work with Git:
Importing the project
In the root directory of a project at your computer, type:
Now, git is able to track files, and you can add them:
- Adding all files:
git add .
# adds the whole project foldergit commit -a
# commits everything
Git opens your text editor where you can enter a commit message. Type the commit message, save the file, and quit.
To abort, just close the file without saving it.
- Tips for finding help
A basic overview of the Git commands can be found with:
Every sub command has a
--helpoption too, for example:
git config --help
You can quit the manual page by pressing q.
There are a few commands to get information about your history:
- Getting information:
# show a log of changesgit status
# see which files you changedgit diff
# view uncommitted changes in the working copygit show commitid
# show one commit
Undoing local changes
There are a few commands to undo local changes:
- Undo local changes:
git checkout filename
# restore original, throw local changes awaygit checkout -f
# throw all local changes away (be careful!)git reset --hard
# the same
That's all you need!
You can use Git for your projects at your computer now. Each time a new feature is complete, you can commit it with git commit -a. New files need to be added first with git add.
In the next chapter, you'll find more tips and insights to fully get up speed.