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).
![](/var/linux_magazin/storage/images/issues/2018/216/version-control-with-git/figure-4/735764-1-eng-US/Figure-4_large.png)
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.