Git Bash (Pull and Push code, track changes and version control)

Published: (January 17, 2026 at 02:42 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Prerequisites

  • A GitHub account
  • Git Bash installed and configured to connect to GitHub
  • An IDE (e.g., Visual Studio Code)

Introduction

Git Bash is a Windows command‑line application that provides a Unix‑like terminal environment for working with Git and GitHub. It lets you run commands to push, pull, commit, or clone repositories hosted on GitHub.

Git is a version‑control system that tracks changes in source code. It records what changed, when, who made the change, and allows you to revert to earlier versions when needed. This enables safe collaboration, prevents accidental loss of work, and makes debugging easier.

Creating a Local Repository

# Initialize a new Git repository in the current folder
git init

# Add all files to the staging area
git add .

# Or add a specific file
git add filename.ext

# Check the repository status
git status

Making the First Commit

git commit -m "Add initial project files"
# Set the default branch name to 'main'
git branch -M main

Connecting to a Remote Repository on GitHub

# Replace <URL> with the URL of your GitHub repository
git remote add origin <URL>

Pushing Code to GitHub

git push -u origin main

You can view the commit history with:

git log

git log shows the commit hash, author, date, and commit message.

Pulling Code from GitHub

Method 1 – Clone (first time)

# Replace <URL> with the URL of the remote repository
git clone <URL>

This creates a folder named after the repository, downloads all files, and sets origin to the GitHub repo.

Method 2 – Pull (subsequent updates)

# Verify you are on the correct branch
git branch

# Pull all updates and merge them into the current branch
git pull

# Or pull a specific branch (e.g., development)
git pull origin development

Tracking Changes

git log

git log displays when commits were made, who made them, and the associated commit messages.

Reverting a Problematic Change

If a recent commit introduces a bug, you can revert it:

# Replace <commit-hash> with the commit hash you want to revert
git revert <commit-hash>

After reverting, push the updated history to keep the remote repository in sync:

git push -u origin main

Summary

You now understand how to:

  • Initialize a local Git repository
  • Commit changes and set a default branch
  • Connect to and push code to a remote GitHub repository
  • Clone and pull updates from GitHub
  • Track commit history with git log
  • Revert unwanted changes

These fundamentals enable effective collaboration and version control for any software project.

Back to Blog

Related posts

Read more »