DEV Community

Cover image for GIT FOR BEGINNERS;
Nkatha Gatobu
Nkatha Gatobu

Posted on

GIT FOR BEGINNERS;

***LEARN TO TRACK, PUSH, PULL LIKE A PRO FOR BEGINNERS.
*
Are you stating on your journey on learning about git and github, below is a simple and detailed step by ste on how to get stared on you coding experience alone or with friends and collegues.

Have you ever worked on a document and wished you could go back to an earlier version?
Collaborated with others and ended up with conflicting changes? Version control solves these problems.
Git is the most popular tool for it. This beginner-friendly guide will help you understand the basics!

What is Version Control?

Think of version control as a super-powered "undo" button for your entire project. It's a system that:

· Tracks every change you make to your code
· Saves snapshots of your project at different points
· Helps teams collaborate without overwriting each other's work
· Lets you experiment safely (you can always go back!)

Understanding Git's Three Areas

Imagine Git has three workspaces:

  1. Working Directory - Where you actually edit files
  2. Staging Area - A "preview" area where you prepare changes
  3. Repository - The permanent storage where Git saves your snapshots

**

Getting Started with Git

**

Step 1: Install and Set Up

  1. Download Git from git-scm.com
  2. Open your terminal/command prompt
  3. Set up your identity:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Your First Repository

A repository (or "repo") is where Git stores your project's history.

# Navigate to your project folder
cd my-project

# Initialize a new Git repository
git init
Enter fullscreen mode Exit fullscreen mode

Congratulations! You now have a Git repository tracking your project.

**

The Essential Git Workflow

Tracking Changes: The Basic Cycle

**

Here's your daily routine with Git:

# 1. Check what you've changed
git status

# 2. Add specific files to staging
git add filename.txt
# Or add all changes
git add .

# 3. Save a snapshot (called a "commit")
git commit -m "Description of what you changed"


**

## Understanding Branches: Parallel Universes for Your Code

**

## Think of branches as parallel timelines for your project:

· Main branch: Your stable, working code
· Feature branches: Where you develop new features without breaking the main code

Enter fullscreen mode Exit fullscreen mode


bash

  1. Create a new branch
  2. git branch feature-login
  3. Switch to that branch
  4. git checkout feature-login
  5. use the shortcut:
  6. git checkout -b feature-login 8. ```

**

Working with Remote Repositories (GitHub/GitLab)

**
Remote repositories are copies of your project stored online (like on GitHub). This enables collaboration and backup.

Setting Up a Remote Connection


bash
# Link your local repo to a remote one
git remote add origin https://github.com/yourname/your-repo.git


Enter fullscreen mode Exit fullscreen mode

Pushing: Sending Your Code to the Cloud


bash
# First push to a new remote repository
git push -u origin main

# Subsequent pushes (after the first)
git push


Enter fullscreen mode Exit fullscreen mode

Pulling: Getting Updates from Others


bash
# Get the latest changes from the remote repository
git pull


Enter fullscreen mode Exit fullscreen mode

git pull is downloading what others have shared.

Common Workflow: Making Changes with a Team


bash
# 1. Always start with the latest code
git pull

# 2. Create a branch for your work
git checkout -b my-new-feature

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

# 4. Push your branch to share it
git push -u origin my-new-feature


Enter fullscreen mode Exit fullscreen mode

Dealing with Common Situations

"I made a mistake in my commit message"


bash
git commit --amend -m "New corrected message"


Enter fullscreen mode Exit fullscreen mode

"I want to see my project's history"


bash
git log --oneline  # Compact view
git log --graph --oneline --all  # Visual history


Enter fullscreen mode Exit fullscreen mode

"I accidentally added a file I don't want to track"


bash
# Remove from staging (but keep the file)
git reset filename.txt

# Stop tracking a file completely
git rm --cached filename.txt


Enter fullscreen mode Exit fullscreen mode

_

Best Practices for Beginners

_

  1. Commit often - Small, frequent commits are better than huge ones
  2. Pull before you start - Always begin with the latest code
  3. Write helpful messages - Explain "why" not just "what"
  4. Use branches - Keep your main branch stable
  5. Don't panic - Git keeps your work safe. You can almost always recover!

**_Remember: Every expert was once a beginner. The more you use Git, the more natural it becomes. Happy coding!

_**

Top comments (0)