Date Created: 2025-05-27
By: 16BitMiker
[ BACK.. ]
Whether you're managing your own codebase or collaborating via a self-hosted Gitea instance, Git remains the cornerstone of modern development workflows. This guide offers a comprehensive, up-to-date walkthrough for setting up Git on Debian, connecting to Gitea via SSH, and mastering the six most essential Git commands. Let's get you running efficiently and securely. ποΈ
For most users, Debian's stable packages are more than sufficient:
sudo apt update
sudo apt install git -y
git --version # Confirm installation
For the latest Git features or when you're customizing the build:
βx# Install required dependencies
sudo apt install wget dh-autoreconf libcurl4-gnutls-dev \
libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto \
docbook2x install-info build-essential
# Download and compile Git
wget https://github.com/git/git/archive/v2.44.0.tar.gz
tar -xf v2.44.0.tar.gz
cd git-2.44.0
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
xxxxxxxxxx
git config --global user.name "Your Full Name"
git config --global user.email "your.email@example.com"
git config --global init.defaultBranch main
git config --global core.editor vim
git config --global color.ui auto
git config --global credential.helper cache --timeout=3600
git config --list # Verify all settings
SSH is the preferred method for secure Git access.
xxxxxxxxxx
ssh-keygen -t ed25519 -C "your.email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub # Copy this to Gitea
In Gitea:
Go to Settings β SSH/GPG Keys
Click βAdd Keyβ β Paste your public key
Save with a descriptive name
Test SSH connection:
xxxxxxxxxx
ssh -T git@your-gitea-instance.com
Click β β βNew Repositoryβ
Set name, description, visibility
Copy the SSH URL for cloning
xxxxxxxxxx
# Clone an existing repo
git clone git@your-gitea-instance.com:username/repo.git
cd repo
# OR initialize a brand new one
mkdir my-project && cd my-project
git init
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"
git remote add origin git@your-gitea-instance.com:username/repo.git
git push -u origin main
git status
β Inspect Your Workspacexxxxxxxxxx
git status # Full status
git status -s # Short version
git status -b # Show current branch
Helps you track staged, unstaged, and untracked changes.
git add
β Stage Changesxxxxxxxxxx
git add file.txt # Add specific file
git add . # Add all files
git add -u # Update tracked files only
git add -A # Include everything
git add -p # Interactive staging
Tip: Use git add -p
to review changes before staging.
git commit
β Save to Local Historyxxxxxxxxxx
git commit -m "Message" # Quick commit
git commit # Opens editor
git commit -am "Message" # Skip staging for tracked files
git commit --amend -m "Updated message" # Modify last commit
Write clear, imperative commit messages:
xxxxxxxxxx
Fix: Handle null pointer in login handler
- Added null check to login function
- Prevents crash on empty form submission
Resolves: #42
git push
β Upload to Remotexxxxxxxxxx
git push -u origin main # First-time push
git push # Regular push
git push origin feature-xyz # Push feature branch
git push --all origin # Push all branches
git push --force-with-lease # Safer force push
Always pull before you push to avoid merge conflicts.
git pull
β Download and Merge Updatesxxxxxxxxxx
git pull # From current branch
git pull origin main # Specify branch
git pull --rebase # Linear history
git pull --autostash # Auto-stash local changes
Tip: Set git config pull.rebase true
for a cleaner commit history.
git clone
β Copy a Remote Repositoryxxxxxxxxxx
git clone git@your-gitea-instance.com:user/repo.git
git clone -b develop ...
git clone --depth 1 ... # Shallow clone
git clone --recursive ... # Include submodules
Use HTTPS only if SSH access is not available.
π From start to finish in a real-world scenario:
xxxxxxxxxx
# Clone project
git clone git@your-gitea-instance.com:user/my-project.git
cd my-project
# Create a branch
git checkout -b feature/auth-module
# Make changes
echo "def login(): pass" > auth.py
# Stage changes
git add auth.py
# Commit
git commit -m "Add login function skeleton"
# Push branch
git push -u origin feature/auth-module
# Merge later
git checkout main
git pull origin main
git merge feature/auth-module
git push origin main
xxxxxxxxxx
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.graph "log --oneline --graph --decorate --all"
Now you can run git st
, git ci -m "..."
, or git graph
.
Avoid committing temp files or build artifacts:
xxxxxxxxxx
# .gitignore
*.pyc
*.log
node_modules/
.vscode/
build/
.env
Add language- and tool-specific entries as needed.
Create a pre-commit
hook to enforce standards:
xxxxxxxxxx
# .git/hooks/pre-commit
echo "Running checks..."
flake8 . || exit 1
Make it executable:
xxxxxxxxxx
chmod +x .git/hooks/pre-commit
xxxxxxxxxx
ssh -T git@your-gitea-instance.com
ssh -Tv git@your-gitea-instance.com # Verbose output
ssh-add -l # Check keys
ssh-add ~/.ssh/id_ed25519 # Re-add key
xxxxxxxxxx
git status
vim conflicted-file.txt # Resolve manually
git add conflicted-file.txt
git commit # Finalize merge
Use git mergetool
for assisted resolution.
xxxxxxxxxx
git restore file.txt # Discard changes
git restore --staged file.txt # Unstage file
git reset --soft HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Undo and discard
git revert abc123 # Revert specific commit
Be cautious with --hard
as it deletes changes permanently.
xxxxxxxxxx
git gc --aggressive # Clean up repo
git clean -fd # Remove untracked files
git remote prune origin # Remove stale branches
git fsck # Check repository health
xxxxxxxxxx
gpg --full-generate-key
gpg --list-secret-keys --keyid-format LONG
git config --global user.signingkey YOUR_KEY_ID
git config --global commit.gpgsign true
To sign commits manually:
xxxxxxxxxx
git commit -S -m "Secure commit"
xxxxxxxxxx
git config --global credential.helper "" # Avoid plaintext storage
git config --global push.default simple
git config --global merge.ff only
git config --global fetch.prune true
Mastering Git on Debian with Gitea integration sets you up for collaborative coding success. With secure SSH access, a clean commit history, and automation via hooks and aliases, you can focus more on building and less on battling your tools. β
Happy hacking! π»