Managing software development projects with Git
Where to Next?
Git is now managing the project, but what is it actually doing? Lets look at the history first, which you can see with git log
. The excerpt from Listing 6 shows a project with two commits, which corresponds to two versions.
Listing 6
Two Commits
$ git log commit 9d71c8dd00db5bfb7e21ac8884356d0af284b1b8 (HEAD -> master) Author: John Doe <john.doe@muster.de> Date: Fri May 11 15:22:13 2018 +0200 new line inserted commit e29f38d1bc7625090 Author: John Doe <john.doe@muster.de> Date: Thu May 10 09:35:53 2018 +0200 First commit
Each commit is identified by a 40-digit SHA1 hash, which I will simply refer to as the hash. The hash is used for unique identification and as a checksum. For some commands, it is possible to specify the hash as a parameter; the first 8 to 10 digits are often sufficient.
The git log 77558e4ac
command will only output the log messages up to the specified commit. In the terminal, you can copy and paste the hash with the mouse by double-clicking the hash with the left mouse button and then pasting it again with a single click on the middle mouse button.
Table 3 contains some commands, including possible options for handling the versioned data. The commands include a multitude of options.
Table 3
Extended Commands
Command | Function |
---|---|
log |
Display versions including hash for identification |
diff |
Display differences between working directory and staging area |
diff --staged |
Display differences between staging area and last commit |
diff hash |
Display differences between working directory and commit hash |
diff hash1 hash2 |
Display differences between the specified commits |
reset HEAD |
Remove files from the staging area |
reset --hard |
Reset files in the working directory to checked-in state |
checkout |
Overwrite file in working directory with content from last commit |
checkout hash |
Check out all files of the specified version .(Note: you cannot modify versions that have already been checked in) |
The git difftool
command behaves like git diff
but starts an external program (Figure 5). Use the command
git config --global diff.tool Program_name
to define the external program if required.
Remote Repository
So far, the project consists only of a local repository in the project directory. However, a typical project usually comes from a remote repository.
To create a remote repository, first create a bare repository from the local data. Unlike the local repo, this does not contain a working directory.
You then have the option to move the bare repository to a corresponding directory, ~/gitrepo
in Listing 7. You can then rename or delete the existing project directory. Simply clone the newly created remote repository, and Git creates the subdirectory.
Listing 7
Remote Repository
$ cd ~/mproject/../ $ git clone --bare mproject mproject.git Clone in bare repository 'mproject.git' ... $ mv mproject.git gitrepo $ cd $ mkdir gitrepo $ mv mproject/ mproject_old $ cd $ git clone /home/john/gitrepo/mproject.git Clone to 'mproject' ... $ cd mproject $ git remote show origin * Remote repository origin URL for retrieval: /home/john/gitrepo/project.git URL for sending: /home/john/gitrepo/project.git Main branch: master Remote branch: master followed Local branch configured for 'git pull': master merges with remote branch master Local reference configured for 'git push': master sent to master (current)
From now on, you will be editing the project in the newly created mproject
directory. The local repository is connected to the remote gitrepo/mproject
repository. The git push
command transfers the data from the local directory to the remote directory.
Conclusions
Using Git is quite simple, even without prior knowledge of version control systems. You can complete your daily work efficiently at the command line with just a few commands. And since Git usually saves the changes locally, commands execute quickly.
Infos
- Git website: https://git-scm.com
- Wikipedia on Git: https://en.wikipedia.org/wiki/Git
- An Interview with Linus Torvalds: https://techcrunch.com/2012/04/19/an-interview-with-millenium-technology-prize-finalist-linus-torvalds/
- Wikipedia definition of a software repository: https://en.wikipedia.org/wiki/Software_repository
« Previous 1 2 3
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
-
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.