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)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.