+
+
webpack
+
json
+
rb
+
android
+
protobuf
+
+
+
+
suse
rubymine
+
bash
%
+
keras
remix
...
zorin
+
emacs
delphi
+
+
phoenix
+
+
>=
https
+
{}
+
+
+
+
+
aws
+
+
ubuntu
+
+
+
+
swc
dart
smtp
+
+
soap
+
+
abap
+
sql
grpc
swift
+
react
parcel
xml
babel
webstorm
+
toml
+
+
+
android
+
rs
||
+
adonis
clj
+
ember
echo
pinecone
rocket
+
+
+
bundler
Back to Blog
๐Ÿ”€ Git Version Control and Workflows on AlmaLinux: Master Your Code
AlmaLinux Git Version Control

๐Ÿ”€ Git Version Control and Workflows on AlmaLinux: Master Your Code

Published Aug 22, 2025

Master Git on AlmaLinux. Install Git, configure repositories, implement branching strategies, use advanced workflows, and collaborate effectively with practical examples.

14 min read
0 views
Table of Contents

๐Ÿ”€ Git Version Control and Workflows on AlmaLinux: Master Your Code

โ€œWho broke the code?!โ€ ๐Ÿ˜ฑ That was me, every Monday morning before Git! Lost work, overwritten files, merge nightmares - sound familiar? Then I discovered Git workflows and everything changed. Now our team of 20 developers ships features daily without conflicts! Today Iโ€™m showing you how to master Git on AlmaLinux and implement professional workflows. Say goodbye to code chaos! ๐ŸŽฏ

๐Ÿค” Why Git is Non-Negotiable

Git isnโ€™t optional anymore - itโ€™s essential! Hereโ€™s why everyone uses it:

  • ๐Ÿ“ Complete history - Every change tracked forever
  • ๐Ÿ”„ Branching magic - Work on features without breaking main
  • ๐Ÿ‘ฅ Perfect collaboration - Multiple developers, zero conflicts
  • โฐ Time travel - Undo mistakes instantly
  • ๐ŸŒ Distributed - Every clone is a full backup
  • ๐Ÿš€ Industry standard - GitHub, GitLab, Bitbucket

True story: We lost 3 weeks of work to a hard drive crash. Never again! Now with Git, even if our servers explode, we have 20+ full backups! ๐Ÿ’ช

๐ŸŽฏ What You Need

Before we version control everything, ensure you have:

  • โœ… AlmaLinux server or workstation
  • โœ… Terminal access
  • โœ… Internet connection for remote repos
  • โœ… 30 minutes to become a Git master
  • โœ… Code to version (anything works!)
  • โœ… Coffee (Git needs focus! โ˜•)

๐Ÿ“ Step 1: Install and Configure Git

Letโ€™s get Git ready for action!

Install Git

# Install Git and useful tools
sudo dnf install -y git git-lfs gitk git-gui

# Check version
git --version

# Install additional tools
sudo dnf install -y tig  # Text-mode interface for Git
sudo dnf install -y git-extras  # Extra Git commands
sudo dnf install -y git-flow  # Git Flow workflow

# Install diff/merge tools
sudo dnf install -y meld kdiff3 vim

Configure Git Identity

# Set your identity (REQUIRED!)
git config --global user.name "John Doe"
git config --global user.email "[email protected]"

# Configure editor
git config --global core.editor vim

# Configure colors
git config --global color.ui auto
git config --global color.branch auto
git config --global color.diff auto
git config --global color.status auto

# Useful aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual '!gitk'
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

# Configure line endings
git config --global core.autocrlf input  # Linux/Mac
# git config --global core.autocrlf true  # Windows

# Default branch name
git config --global init.defaultBranch main

# Configure merge tool
git config --global merge.tool meld
git config --global mergetool.meld.path /usr/bin/meld

# View all settings
git config --list

SSH Key Setup for GitHub/GitLab

# Generate SSH key
ssh-keygen -t ed25519 -C "[email protected]"
# Press Enter for default location
# Enter passphrase (optional but recommended)

# Start SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Copy public key
cat ~/.ssh/id_ed25519.pub
# Add this to GitHub/GitLab SSH keys

# Test connection
ssh -T [email protected]
ssh -T [email protected]

# Configure SSH for multiple accounts
cat > ~/.ssh/config << 'EOF'
# Personal GitHub
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519

# Work GitLab
Host gitlab-work
    HostName gitlab.company.com
    User git
    IdentityFile ~/.ssh/id_rsa_work
    
# Personal GitLab
Host gitlab-personal
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_ed25519_personal
EOF

๐Ÿ”ง Step 2: Git Basics and Best Practices

Master the essential commands! ๐ŸŽฎ

Initialize and Clone Repositories

# Initialize new repository
mkdir myproject && cd myproject
git init

# Clone existing repository
git clone https://github.com/user/repo.git
git clone [email protected]:user/repo.git  # SSH

# Clone with specific branch
git clone -b develop https://github.com/user/repo.git

# Shallow clone (faster for large repos)
git clone --depth 1 https://github.com/user/repo.git

Basic Workflow

# Check status
git status
git status -s  # Short format

# Add files
git add file.txt  # Specific file
git add .  # All files
git add -A  # All files including deletions
git add -p  # Interactive staging

# Commit changes
git commit -m "Add new feature"
git commit -am "Fix bug"  # Add and commit
git commit --amend  # Modify last commit

# View history
git log
git log --oneline
git log --graph --oneline --all
git log -p  # Show patches
git log --stat  # Show statistics

# View differences
git diff  # Working directory vs staging
git diff --staged  # Staging vs last commit
git diff HEAD  # Working directory vs last commit
git diff branch1..branch2  # Between branches

# Undo changes
git checkout -- file.txt  # Discard changes
git reset HEAD file.txt  # Unstage
git reset --soft HEAD~1  # Undo last commit, keep changes
git reset --hard HEAD~1  # Undo last commit, discard changes
git revert commit-hash  # Create new commit that undoes

Branch Management

# List branches
git branch  # Local branches
git branch -r  # Remote branches
git branch -a  # All branches

# Create branch
git branch feature-xyz
git checkout -b feature-xyz  # Create and switch

# Switch branches
git checkout main
git switch develop  # Newer command

# Merge branches
git checkout main
git merge feature-xyz
git merge --no-ff feature-xyz  # No fast-forward

# Delete branch
git branch -d feature-xyz  # Safe delete
git branch -D feature-xyz  # Force delete
git push origin --delete feature-xyz  # Delete remote

# Rename branch
git branch -m old-name new-name

๐ŸŒŸ Step 3: Professional Git Workflows

Implement team workflows! ๐Ÿ‘ฅ

Git Flow Workflow

# Initialize Git Flow
git flow init

# Start new feature
git flow feature start new-feature
# Work on feature...
git add .
git commit -m "Implement new feature"

# Finish feature
git flow feature finish new-feature

# Start release
git flow release start 1.0.0
# Prepare release...
git flow release finish 1.0.0

# Hotfix
git flow hotfix start fix-critical-bug
# Fix bug...
git flow hotfix finish fix-critical-bug

# Manual Git Flow (without extension)
# Main branches: main (production) and develop

# Feature branch
git checkout -b feature/user-auth develop
# Work on feature
git checkout develop
git merge --no-ff feature/user-auth
git branch -d feature/user-auth

# Release branch
git checkout -b release/1.0.0 develop
# Prepare release
git checkout main
git merge --no-ff release/1.0.0
git tag -a v1.0.0 -m "Version 1.0.0"
git checkout develop
git merge --no-ff release/1.0.0

GitHub Flow (Simpler)

# 1. Create branch from main
git checkout -b feature-xyz main

# 2. Make changes and commit
git add .
git commit -m "Add new feature"

# 3. Push to remote
git push -u origin feature-xyz

# 4. Create Pull Request (on GitHub/GitLab)

# 5. After review and approval, merge to main
git checkout main
git pull origin main
git merge feature-xyz
git push origin main

# 6. Delete feature branch
git branch -d feature-xyz
git push origin --delete feature-xyz

GitLab Flow

# Environment branches
# main -> staging -> production

# Feature development
git checkout -b feature/new-feature main
# Develop feature
git push -u origin feature/new-feature

# Merge to main (development)
git checkout main
git merge feature/new-feature

# Deploy to staging
git checkout staging
git merge main
git push origin staging

# Deploy to production
git checkout production
git merge staging
git tag -a v1.0.0 -m "Release v1.0.0"
git push origin production --tags

โœ… Step 4: Advanced Git Techniques

Level up your Git game! ๐Ÿš€

Interactive Rebase

# Clean up commit history
git rebase -i HEAD~3

# In editor, you can:
# pick = use commit
# reword = change message
# edit = stop for amending
# squash = combine with previous
# fixup = like squash but discard message
# drop = remove commit

# Example: squash last 3 commits
git rebase -i HEAD~3
# Change 'pick' to 'squash' for commits 2 and 3
# Save and write new commit message

Cherry-Pick

# Apply specific commit to current branch
git cherry-pick commit-hash

# Cherry-pick range
git cherry-pick commit1..commit2

# Cherry-pick without committing
git cherry-pick -n commit-hash

Stashing

# Save work temporarily
git stash
git stash save "WIP: working on feature"

# List stashes
git stash list

# Apply stash
git stash apply  # Keep stash
git stash pop  # Apply and remove

# Apply specific stash
git stash apply stash@{2}

# Show stash contents
git stash show -p stash@{0}

# Create branch from stash
git stash branch new-branch stash@{0}

# Clear all stashes
git stash clear

Git Hooks

# Create pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
# Run tests before commit

echo "Running tests..."
npm test

if [ $? -ne 0 ]; then
    echo "Tests failed! Commit aborted."
    exit 1
fi

echo "Tests passed!"
EOF

chmod +x .git/hooks/pre-commit

# Create commit message hook
cat > .git/hooks/commit-msg << 'EOF'
#!/bin/bash
# Enforce commit message format

commit_regex='^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .{1,50}'

if ! grep -qE "$commit_regex" "$1"; then
    echo "Invalid commit message format!"
    echo "Format: type(scope): subject"
    echo "Example: feat(auth): add login functionality"
    exit 1
fi
EOF

chmod +x .git/hooks/commit-msg

๐ŸŽฎ Quick Examples

Example 1: Team Collaboration Script ๐Ÿ‘ฅ

#!/bin/bash
# Git collaboration helper

cat > /usr/local/bin/git-team << 'EOF'
#!/bin/bash

case "$1" in
    sync)
        echo "๐Ÿ”„ Syncing with team..."
        git fetch --all --prune
        git pull --rebase origin main
        echo "โœ… Synced with latest changes"
        ;;
        
    feature)
        if [ -z "$2" ]; then
            echo "Usage: git-team feature <name>"
            exit 1
        fi
        echo "๐ŸŒŸ Creating feature branch: feature/$2"
        git checkout -b feature/$2 main
        git push -u origin feature/$2
        echo "โœ… Feature branch created and pushed"
        ;;
        
    review)
        echo "๐Ÿ“ Preparing for code review..."
        git fetch origin
        git log origin/main..HEAD --oneline
        echo ""
        echo "Files changed:"
        git diff origin/main --name-only
        echo ""
        echo "Diff statistics:"
        git diff origin/main --stat
        ;;
        
    cleanup)
        echo "๐Ÿงน Cleaning up merged branches..."
        git checkout main
        git pull origin main
        
        # Delete local merged branches
        git branch --merged | grep -v "\*\|main\|develop" | xargs -n 1 git branch -d
        
        # Delete remote tracking branches
        git remote prune origin
        echo "โœ… Cleanup complete"
        ;;
        
    status)
        echo "๐Ÿ“Š Team Repository Status"
        echo "========================="
        echo "Current branch: $(git branch --show-current)"
        echo "Last commit: $(git log -1 --oneline)"
        echo ""
        echo "Local branches:"
        git branch
        echo ""
        echo "Remote branches:"
        git branch -r
        echo ""
        echo "Recent activity:"
        git log --oneline -10 --graph --all
        ;;
        
    *)
        echo "Git Team Helper"
        echo "Usage: git-team {sync|feature|review|cleanup|status}"
        echo ""
        echo "  sync     - Sync with remote repository"
        echo "  feature  - Create new feature branch"
        echo "  review   - Prepare for code review"
        echo "  cleanup  - Remove merged branches"
        echo "  status   - Show repository status"
        ;;
esac
EOF

chmod +x /usr/local/bin/git-team

# Usage
git-team sync
git-team feature user-authentication
git-team review

Example 2: Automated Release Manager ๐Ÿš€

#!/bin/bash
# Automated release workflow

cat > /usr/local/bin/git-release << 'EOF'
#!/bin/bash

VERSION=$1
CURRENT_BRANCH=$(git branch --show-current)

if [ -z "$VERSION" ]; then
    echo "Usage: git-release <version>"
    echo "Example: git-release 1.2.0"
    exit 1
fi

echo "๐Ÿš€ Starting release process for v$VERSION"

# Ensure we're on develop
if [ "$CURRENT_BRANCH" != "develop" ]; then
    echo "โš ๏ธ Switching to develop branch..."
    git checkout develop
fi

# Update from remote
echo "๐Ÿ”„ Updating develop branch..."
git pull origin develop

# Create release branch
echo "๐ŸŒฟ Creating release branch..."
git checkout -b release/$VERSION

# Update version in files
echo "๐Ÿ“ Updating version numbers..."
sed -i "s/version=\".*\"/version=\"$VERSION\"/" package.json
sed -i "s/VERSION = .*/VERSION = '$VERSION'/" config.py
echo "v$VERSION" > VERSION

# Commit version changes
git add -A
git commit -m "chore: bump version to $VERSION"

# Run tests
echo "๐Ÿงช Running tests..."
npm test
if [ $? -ne 0 ]; then
    echo "โŒ Tests failed! Aborting release."
    git checkout develop
    git branch -D release/$VERSION
    exit 1
fi

# Build project
echo "๐Ÿ”จ Building project..."
npm run build

# Generate changelog
echo "๐Ÿ“œ Generating changelog..."
git log --pretty=format:"- %s" develop..HEAD > CHANGELOG_TEMP.md
cat CHANGELOG_TEMP.md CHANGELOG.md > CHANGELOG_NEW.md
mv CHANGELOG_NEW.md CHANGELOG.md
rm CHANGELOG_TEMP.md

echo "## Version $VERSION - $(date +%Y-%m-%d)" | cat - CHANGELOG.md > temp
mv temp CHANGELOG.md

git add CHANGELOG.md
git commit -m "docs: update changelog for v$VERSION"

# Merge to main
echo "๐Ÿ”€ Merging to main..."
git checkout main
git pull origin main
git merge --no-ff release/$VERSION -m "release: v$VERSION"

# Create tag
echo "๐Ÿท๏ธ Creating tag..."
git tag -a v$VERSION -m "Release version $VERSION"

# Merge back to develop
echo "๐Ÿ”€ Merging back to develop..."
git checkout develop
git merge --no-ff release/$VERSION -m "Merge release v$VERSION back to develop"

# Push everything
echo "๐Ÿ“ค Pushing to remote..."
git push origin main
git push origin develop
git push origin --tags

# Cleanup
echo "๐Ÿงน Cleaning up..."
git branch -d release/$VERSION

echo "โœ… Release v$VERSION completed successfully!"
echo ""
echo "๐Ÿ“ฆ Don't forget to:"
echo "  - Create GitHub/GitLab release"
echo "  - Deploy to production"
echo "  - Notify team"
EOF

chmod +x /usr/local/bin/git-release

# Usage
git-release 1.2.0

Example 3: Git Statistics Dashboard ๐Ÿ“Š

#!/bin/bash
# Git repository analytics

cat > /usr/local/bin/git-stats << 'EOF'
#!/bin/bash

echo "๐Ÿ“Š Git Repository Statistics"
echo "============================"
echo ""

# Repository info
echo "๐Ÿ“ Repository Information:"
echo "  Name: $(basename `git rev-parse --show-toplevel`)"
echo "  Remote: $(git remote get-url origin 2>/dev/null || echo 'No remote')"
echo "  Current Branch: $(git branch --show-current)"
echo "  Total Branches: $(git branch -a | wc -l)"
echo "  Total Tags: $(git tag | wc -l)"
echo "  Total Commits: $(git rev-list --all --count)"
echo ""

# Contributors
echo "๐Ÿ‘ฅ Top Contributors (by commits):"
git shortlog -sn | head -10
echo ""

# Recent activity
echo "๐Ÿ“… Recent Activity:"
echo "  Commits today: $(git log --since=midnight --oneline | wc -l)"
echo "  Commits this week: $(git log --since='1 week ago' --oneline | wc -l)"
echo "  Commits this month: $(git log --since='1 month ago' --oneline | wc -l)"
echo ""

# File statistics
echo "๐Ÿ“„ File Statistics:"
echo "  Total files: $(git ls-files | wc -l)"
echo "  Lines of code: $(git ls-files | xargs wc -l | tail -1 | awk '{print $1}')"
echo ""
echo "  Top 5 largest files:"
git ls-files | xargs ls -la 2>/dev/null | sort -k5 -rn | head -5 | awk '{print "    " $9 " (" $5 " bytes)"}'
echo ""

# Language breakdown
echo "๐Ÿ’ป Language Breakdown:"
git ls-files | grep -E '\.(js|py|java|cpp|go|rs|rb|php|ts|sh)$' | sed 's/.*\.//' | sort | uniq -c | sort -rn | head -10
echo ""

# Commit patterns
echo "โฐ Commit Time Patterns:"
echo "  By hour of day:"
git log --format="%ad" --date=format:'%H' | sort | uniq -c | sort -k2 -n | head -5 | while read count hour; do
    printf "    %02d:00 - %d commits\n" $hour $count
done
echo ""
echo "  By day of week:"
git log --format="%ad" --date=format:'%A' | sort | uniq -c | sort -rn

# Branch activity
echo ""
echo "๐ŸŒฟ Branch Activity:"
for branch in $(git branch -r | grep -v HEAD); do
    echo "  $branch: $(git log --oneline $branch | wc -l) commits, last: $(git log -1 --format='%ar' $branch)"
done | head -10

# Generate report file
echo ""
echo "๐Ÿ“ Generating detailed report..."
{
    echo "Git Repository Report"
    echo "Generated: $(date)"
    echo "========================"
    echo ""
    git log --pretty=format:'%h - %an, %ar : %s' --graph -20
    echo ""
    echo "File Changes Summary:"
    git diff --stat HEAD~10
} > git-report-$(date +%Y%m%d).txt

echo "โœ… Report saved to git-report-$(date +%Y%m%d).txt"
EOF

chmod +x /usr/local/bin/git-stats

# Run statistics
git-stats

๐Ÿšจ Fix Common Problems

Problem 1: Merge Conflicts โŒ

Files have conflicts?

# View conflicts
git status
git diff

# Resolve manually
vim conflicted-file.txt
# Look for <<<<<<< HEAD

# Or use merge tool
git mergetool

# After resolving
git add conflicted-file.txt
git commit

# Abort merge if needed
git merge --abort

Problem 2: Pushed Wrong Commit โŒ

Need to undo pushed commit?

# Revert (safe - creates new commit)
git revert HEAD
git push

# Reset (dangerous - rewrites history)
git reset --hard HEAD~1
git push --force  # DANGEROUS!

# Better: create fix commit
git commit -m "Fix: undo previous changes"
git push

Problem 3: Lost Changes โŒ

Accidentally deleted work?

# Check reflog
git reflog

# Restore from reflog
git checkout HEAD@{2}

# Find lost commits
git fsck --lost-found

# Recover stashed changes
git stash list
git stash apply stash@{0}

Problem 4: Wrong Branch โŒ

Committed to wrong branch?

# Move commit to correct branch
git checkout correct-branch
git cherry-pick wrong-branch
git checkout wrong-branch
git reset --hard HEAD~1

# Or use rebase
git rebase --onto correct-branch wrong-branch~1 wrong-branch

๐Ÿ“‹ Simple Commands Summary

TaskCommand
๐Ÿ” Statusgit status
โž• Add filesgit add .
๐Ÿ’พ Commitgit commit -m "message"
๐Ÿ“ค Pushgit push origin main
๐Ÿ“ฅ Pullgit pull origin main
๐ŸŒฟ New branchgit checkout -b feature
๐Ÿ”€ Mergegit merge feature
๐Ÿ“œ Historygit log --oneline

๐Ÿ’ก Tips for Success

  1. Commit Often ๐Ÿ’พ - Small commits are better
  2. Write Good Messages ๐Ÿ“ - Future you will thank you
  3. Branch Everything ๐ŸŒฟ - Never work on main
  4. Pull Before Push ๐Ÿ“ฅ - Avoid conflicts
  5. Use .gitignore ๐Ÿšซ - Donโ€™t track everything
  6. Backup Important Branches ๐Ÿ’พ - Push to multiple remotes

Pro tip: Use git reflog to recover from almost any mistake. Itโ€™s saved me countless times! ๐Ÿฆธ

๐Ÿ† What You Learned

Youโ€™re now a Git ninja! You can:

  • โœ… Install and configure Git
  • โœ… Use essential commands
  • โœ… Implement team workflows
  • โœ… Handle branches and merges
  • โœ… Resolve conflicts
  • โœ… Use advanced techniques
  • โœ… Automate workflows

๐ŸŽฏ Why This Matters

Git provides:

  • ๐Ÿ“ Complete code history
  • ๐Ÿ‘ฅ Seamless collaboration
  • ๐Ÿ”„ Safe experimentation
  • โฐ Easy rollbacks
  • ๐ŸŒ Distributed backup
  • ๐Ÿš€ Professional workflow

Last week, a junior dev accidentally deleted our entire codebase. Recovery time? 30 seconds with git reset --hard. Without Git? Weโ€™d still be crying! ๐Ÿ˜ญโžก๏ธ๐Ÿ˜Š

Remember: In Git we trust, everything else we commit! ๐Ÿ”€

Happy versioning! May your commits be atomic and your merges be clean! ๐Ÿš€โœจ