DEV Community

@waruikelvin
@waruikelvin

Posted on

Getting Started with Git: Track Your Code and Use GitHub with Confidence

Image

Introduction

Hey! Are you learning to code? Have you heard people talk about Git and GitHub? How did you feel when you first heard those terms? Why do developers need them? What problems do they actually solve? And how do commands like push and pull fit in?

This article is written for absolute beginners who want a simple, practical introduction to Git and GitHub. You don’t need any prior experience with version control, and you don’t need to be an expert developer.

By the end of this article, you’ll understand:

  • What Git is and why version control is important
  • How to track changes in your code using Git
  • How to push your code to GitHub
  • How to pull code from GitHub

Think of Git as a safety net for your code. It helps you keep track of changes, avoid losing work, and collaborate with others confidently. Let’s break it down step by step, in plain language.

Common Git Terms You Will See

When learning Git and GitHub, you’ll come across new terms. Don’t worry, here are simple explanations to help you understand them.

  1. Repository (Repo) – A folder that contains your project and its full change history.
  2. Commit – A saved snapshot of your project at a specific point in time.
  3. Branch – A separate version of your project used to work on features or fixes safely.
  4. Main (or Master) – The primary branch containing the stable version of the project.
  5. Remote Repository – A version of your project stored online (for example, on GitHub).
  6. Staging Area – A place where files are prepared before committing.
  7. Push – Sending local commits to a remote repository like GitHub.
  8. Pull – Downloading the latest changes from a remote repository.
  9. Clone – Creating a local copy of a remote repository.
  10. Statusgit status shows the state of your files (new, modified, or staged).

What Is Git?

Git is a distributed version control system used to track changes in source code during software development.

Instead of saving multiple copies of your project, like:

project-v1
project-v2
project-final-version
Enter fullscreen mode Exit fullscreen mode

Git automatically keeps a complete history of your work.

Each time you make a meaningful change, you can save a snapshot called a commit. If something breaks later, you can easily go back to a previous version that worked.

Git vs GitHub

Git

  • Runs on your local computer
  • Tracks changes and manages versions locally

GitHub

  • An online platform
  • Stores Git repositories in the cloud
  • Helps developers collaborate and share code

NOTE: You can use Git without GitHub, but GitHub makes collaboration and backups much easier.

Why Is Version Control Important?

Version control (also called source control) is the practice of tracking and managing changes to code.

It helps you:

  1. Avoid losing your code
  2. See what changed and when
  3. Experiment without fear
  4. Collaborate with others
  5. Go back to earlier versions if something breaks

Tracking Changes Using Git

Let’s look at the basic Git workflow.

1. Initialize a Git Repository

Inside your project folder, run:

git init
Enter fullscreen mode Exit fullscreen mode

This tells Git to start tracking your project.

2. Check the Status of Your Files

git status
Enter fullscreen mode Exit fullscreen mode

This shows which files are new, modified, or ready to be committed.

3. Add Files to the Staging Area

Before saving changes, you need to stage them:

git add .
Enter fullscreen mode Exit fullscreen mode

This stages all changed files.

4. Commit Your Changes

A commit saves a snapshot of your project:

git commit -m "Add initial project files."
Enter fullscreen mode Exit fullscreen mode

Creating a GitHub Repository

To push your code online, you’ll need a GitHub repository.

  1. Go to github and sign in or sign up
  2. Click New Repository
  3. Choose a repository name and visibility (public or private)
  4. Create the repository

NOTE: Don’t initialize with a README if your project already exists.
GitHub will give you a repository URL.


How to Push Code to GitHub

1. Connect Your Local Project to GitHub

Replace the URL with your own repository URL:

git remote add origin https://github.com/username/repository-name.git
Enter fullscreen mode Exit fullscreen mode

2. Push Your Code

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

After this, your code will appear on GitHub.

How to Pull Code from GitHub

When working with others or switching computers, you’ll need to pull the latest changes:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Always pull before starting new work to avoid conflicts.

Common Beginner Mistakes

Making mistakes while learning Git is completely normal; even experienced developers make them.

Common mistakes include:

  1. Forgetting to commit before pushing
  2. Confusing Git (local) with GitHub (online)
  3. Not pulling before making changes
  4. Writing unclear commit messages

Learning Git takes practice, so be patient with yourself.

Useful Git commands to remember

git init        # Start a Git repository
git status      # Check file status
git add .       # Stage changes
git commit -m   # Save changes
git push        # Upload to GitHub
git pull        # Download updates
git log         # View commit history
Enter fullscreen mode Exit fullscreen mode

Conclusion

Git is one of the most important tools you’ll learn as a developer. It helps you track changes, protect your work, and collaborate with confidence.

Start small, practice often, and don’t be afraid to make mistakes. Git is designed to help you recover from them.

Happy coding!

Top comments (0)