Using Git

Configuring a Remote Git Mirror

Git provides source tracking for system configuration files. You host repositories on private servers to ensure data sovereignty. This setup avoids reliance on third-party cloud providers.

The following steps configure a basic remote mirror. The process utilizes standard secure shell connections. You need a functioning Linux server. You must possess administrative credentials on that host.

  1. Connect to the remote server. Create a dedicated system user. Execute sudo adduser git.
  2. Construct a storage directory for the repositories. Create /var/repos/git and assign ownership to the new user.
  3. Establish authentication. Append your local public key to the .ssh/authorized_keys file for the git user.
  4. Prepare the project directory. For a local project named myrepo, create /var/repos/git/myrepo.git. Assign ownership to the git user.
  5. Initialize the remote structure. Switch to the git user. Navigate into the new directory. Issue the command git init --bare.
  6. Connect the local repository. On your workstation, navigate into the project directory. Issue the command git remote add myremotename git@myserver:/var/repos/git/myrepo.git.
  7. Transmit the data. Issue the command git push -u myremotename main.

This establishes a private mirror on sovereign infrastructure.

Useful Operations and Commands

Developers encounter complex scenarios during daily version control procedures. These commands resolve common repository states.

Undo the Latest Commit

git reset HEAD~1

This command removes the latest commit from the history. It preserves the file modifications in your working directory. You use this to reformat a change or add forgotten files.

Prune Stale Remote Tracking Branches

git fetch -p

Team members delete branches on the central server after merging pull requests. Your local repository retains stale tracking references. This command synchronizes the state and removes references to deleted remote branches.

Stash Untracked Files

git stash push -u

The basic stash operation ignores new files. The -u flag instructs Git to include untracked assets in the temporary storage mechanism.

View a Visual Commit Graph

git log --graph --oneline --all

Visualizing branching paths requires a precise log format. This combination of flags produces a concise graphical representation of the commit tree across all branches.

Search Commit Content

git log -S "search string"

You need to locate the commit that introduced or removed a specific piece of code. The -S flag inspects the differences of every commit for the provided string.