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
-
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.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.