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
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
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.