Managing software development projects with Git
Versions
A Git-versioned project keeps three versions of a file. The version in the working directory is the one you work on. Once the file has reached a state that you want to keep, transfer it to the staging area using git add file
and continue working on the version in the working directory.
You can repeat this process as often as you like. However, you always overwrite the previous version in the staging area. There is exactly one version for each file in the staging area. Any following commits adopt this latest version. The version in the working directory is irrelevant.
Figure 2 shows two different versions of the file project.txt
, one in the staging area and a second in the working directory. The repository contains the third version.
Git sometimes gives hints when executing some commands. The hints often refer to how you undo a particular action.
Help
In addition to the general manual (man git
), the installation comes with several specific manuals (see Table 1). If you call man git
, you will find an overview of the subcommands, including a short description in the GIT COMMANDS
section (Figure 3).
Table 1
All Cases Covered
Call | Content |
---|---|
man gittutorial |
Git-based project flow |
man giteveryday |
Frequently used commands, including examples (Fedora) |
man gitcore-tutorial |
Procedure in detail; partly using outdated commands |
man git |
General manual |
Further documentation is located in /usr/share/doc/git
. The scope of the documentation depends on the distribution. Fedora comes with a manual for users, user-manual.html
, and a how-to, howto-index.html
.
For help with a subcommand, add the subcommand with a hyphen. For instance, man git-add
brings up information on the git add
command (Figure 4).
All distributions used in the test support automatic completion of the Git commands and their options using the Tab key. The excerpt from Listing 4, Line 2, shows the output after the command git a
followed by pressing Tab. In this case, several options appear. The call to git --help
(Listing 4, Line 3) shows an excerpt from the overview of the Git commands by task.
Listing 4
Completion and Help
01 $ git a 02 add am annotate apply archive 03 $ git --help 04 Use: git ... <command> [<args>]
Continuing with the Project
The project.txt
file changes as the project progresses. You copy and save new versions with the commands add
and commit
. The git status
command shows the status of the files in the working directory. Listing 5 shows the status of the file after the git add project.txt
command switches from changes that are not flagged for a commit to changes that are flagged for commit.
Listing 5
Project File Status
$ echo "new line" >> project.txt $ git status On Branch master Changes not flagged for commit: (use"git add <File>..." to flag the changes for the commit) (use "git checkout -- <File>..." to discard the changes in the working directory) changed: project.txt no changes are flagged for commit (use "git add" and/or "git commit -a") $ git add project.txt $ git status On Branch master changes flagged for commit: (Use "git reset HEAD <File>..." to remove from the staging area) changed: project.txt $ git commit -m "new line inserted" [master 9d71c8d] new line inserted 1 file changed, 1 insertion(+)
The git add
command lets users specify patterns for files and directories and other options. You can use git add -u
to move all modified files entered in the index into the staging area. Table 2 shows the commands used so far.
Table 2
Getting Started
Command | Function |
---|---|
init |
Create or initialize empty repository |
add |
Add files to the staging area (basis for a commit) |
commit |
Transfer staging area versions to repository |
status |
Request status of files in working directory |
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)