No results found

Try a different search query

Popular searches:

Add to Cart

Cart

You have no purchases yet

Browse Marketplace

Git for Beginners: Complete Guide

Everything you need to know about Git: from basic commands to branching and conflict resolution.

10 min read
6,744
5
7
Git for Beginners: Complete Guide

Git is a version control system that is the standard in modern development. If you're not using Git yet, this guide will help you get started.

Installation and Setup

# Ubuntu/Debian
sudo apt install git

# Check version
git --version

# Basic configuration
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main

Basic Commands

Creating a Repository

# Initialize new repository
git init

# Clone existing one
git clone https://github.com/user/repo.git

Workflow

# Check status
git status

# Add files to staging
git add filename.php
git add .  # all files

# Create commit
git commit -m "Description of changes"

# Push to server
git push origin main

# Pull changes from server
git pull origin main

Write meaningful commit messages. "fix bug" — bad. "Fix product price calculation for discounted items" — good.

— Common practice

Working with Branches

Branches allow you to work on different features in parallel:

# Create new branch
git branch feature/new-payment

# Switch to branch
git checkout feature/new-payment

# Or create and switch at once
git checkout -b feature/new-payment

# List branches
git branch -a

# Delete branch
git branch -d feature/old-branch
Tip: Use branch naming convention: feature/, bugfix/, hotfix/

Merging Branches

# Switch to main
git checkout main

# Merge feature branch
git merge feature/new-payment

# If there are conflicts — resolve them in files
# Then:
git add .
git commit -m "Merge feature/new-payment"

Resolving Conflicts

Conflicts occur when the same lines are changed in different branches:

<<<<<<< HEAD
$price = $product->getPrice();
=======
$price = $product->getDiscountedPrice();
>>>>>>> feature/discounts

Remove the markers and keep the needed code, then commit.

Useful Commands

# Commit history
git log --oneline

# Discard uncommitted changes
git checkout -- filename.php

# Remove file from staging
git reset HEAD filename.php

# Amend last commit
git commit --amend -m "New description"

# Temporary save changes
git stash
git stash pop

.gitignore

File to exclude files from the repository:

# .gitignore for OpenCart
/config.php
/admin/config.php
/system/storage/
/image/catalog/
*.log
.env
/vendor/
/node_modules/
Important: Never commit sensitive data: passwords, API keys, configurations with credentials.

Conclusion

Git is a powerful tool, and these basic commands cover 90% of daily needs. Practice, and soon Git will become your reliable development companion.

DEV Тестовий

DEV Тестовий

Привіт! Я досвідчений розробник з OpenCart екосистеми з понад 10 роками практики. Технічний стек включає PHP (core мова для OpenCart), MySQL/MariaDB для баз даних, JavaScript/jQuery для фронтенду, HTML5/CSS3/Bootstrap для верстки. Маю глибокий досвід роботи з архітектурою OpenCart (MVC, Event System, OCMOD), інтеграцією платіжних систем та API, оптимізацією продуктивності магазинів. Окрім розробки, займаюся серверним адмініструванням — Linux (Ubuntu/Debian), Apache/Nginx, налаштування VPS/Dedicated серверів, DNS менеджмент, SSL сертифікати, email. Обслуговую понад 5000 інтернет-магазинів по всьому світу, надаючи комплексні рішення від розробки до технічної підтримки.

articles
12
views
53,920
likes
63
followers
3

Related Posts

Comments (7)

Replying to

Please log in to leave a comment

Log In
OCTemplates
Чи можна відновити видалену гілку?
OCTemplates
Дякую, нарешті зрозумів різницю між merge і rebase.
m
Як правильно вирішувати merge conflicts?

We use cookies

We use cookies and similar technologies to improve your experience, analyse traffic, and show personalised ads. Read our Cookie Policy for details.