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
-
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.