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
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.