MaruOpsInfrastructure and AI notes

About (Korean)Contact (Korean)

[Git and GitOps 04] Install Git and Prepare a Repository on Ubuntu 24.04

Wooden desk with laptop and mug

Reference photo · Wooden desk with laptop and mug · Photo: Ryan Riggins ryan_riggins / Source / CC0 · Resized for listings; illustrative photo, not the tested environment

Ubuntu 24.04 provides Git through its normal APT repositories. Refresh the package list, install Git and the SSH client, then check the version that actually runs. This gives the lab a straightforward package-managed starting point.

The exercise is based on a terminal with a regular account capable of sudo. Installation and Git operation were verified in the Ubuntu 24.04 container, and installation of the WSL distribution or manipulation of the Windows screen was not included in this verification.

Git · GitOps All Series · 04 / 24

On this page

1. Update the package list and install

cat /etc/os-release
sudo apt update
apt-cache policy git
sudo apt install -y git openssh-client ca-certificates
git --version
command -v git

apt update is a command that retrieves a new package list and does not upgrade all installed programs. Candidate by apt-cache policy git is the version currently selected as a candidate for installation in the repository. In the actual verification environment, Git 2.43.0 was installed.

If a signature or certificate error occurs, the verification option will not be turned off. Check the system view, CA certificate, storage address, and certificate distribution status of your on-premise proxy. Git installation issues and subsequent Git server authentication issues are separate issues.

2. Specify creation information and default branch

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --show-origin --get user.name
git config --show-origin --get user.email

main is the first branch name used in this series. If your existing project uses master or a different name, you do not need to change it during installation. Changing the default branch can also affect remote servers, protection rules, and CI settings.

Your name and email will be included in your commit history. Even in private repositories, commits you forward externally may contain information and are subject to your company’s account policies. If the values ​​are different for your personal and work projects, the local settings for each repository will be used.

3. Create a working folder in your home directory

mkdir -p ~/git-lab
cd ~/git-lab
mkdir ubuntu-check
cd ubuntu-check
git init -b main
printf '# Ubuntu Git lab\n' > README.md
git add README.md
git commit -m "Add Ubuntu lab README"
git log -1 --oneline
git status --short --branch

The commit hash depends on when it was executed and what information it wrote. This value does not have to be the same as the example hash in the document. If there are no file changes in the last state and the branch is main, you have left a local record.

If Permission denied appears, check from pwd, id, and ls -ld . .git. Prefixing a Git command with sudo may cause further ownership issues in subsequent operations. Server storage and personal work folders on the system path separate administrative entities.

Differences between WSL and server Ubuntu

The commands for Git are the same, but where you keep the files and which account your SSH keys are in are different. ~/.ssh in a WSL terminal and .ssh in a Windows user are not assumed to be in the same location. Git Credential Manager and SSH Agent must also be connected by checking the actual environment in use.

On server Ubuntu, commits already made are not lost even if SSH connection is lost. However, if you do not push it to another server, the history only remains on that server’s disk. Don’t confuse server snapshots or file backups with Git remote repositories.

Separate PPA is chosen when the need arises.

Even if the distribution version is lower than the latest version on the official site, it does not immediately indicate an incorrect installation. This decision is based on whether the required commands are supported and the distribution’s security update policy. If new functionality is required, verify that the repository is permitted by your organization and note the scope of the change.

After installation, all you need is the git-lab folder to use in Part 5. You can check the installation path for each distribution in Ubuntu’s Git package information and Git’s Linux installation guide.

Previous · [Git and GitOps 03] Install Git and Prepare an Account on Rocky Linux 9 · Next · [Git and GitOps 05] Make a First Commit with add, commit, status and diff · Series list and example files