DEV Community

Edmund Eryuba
Edmund Eryuba

Posted on

An Introduction to Git: Concepts, Commands, and Workflows

Github workflow diagram

What is Git?

Git is a distributed version control system designed to track changes in source code and manage collaboration among developers. It enables individuals and teams to maintain a complete history of a project, revert to previous versions when needed, and work on the same codebase without conflicts. Because each developer has a full copy of the repository, Git offers high performance, reliability, and the ability to work offline. Git is the core technology behind popular platforms such as GitHub, GitLab, and Bitbucket.

Understanding Git Bash

Git Bash is a command-line interface that provides a Unix-like shell environment for using Git on Windows systems. It allows users to run Git commands in a terminal similar to those found on Linux and macOS, making cross-platform development easier. In addition to Git commands, Git Bash supports basic shell operations such as navigating directories, creating files, and managing folders, which are commonly used during development workflows.

Initializing and Managing a Repository

To begin tracking a project with Git, a repository is initialized using the git init command. This creates a hidden .git directory that stores all version history and configuration data. Files are then added to the staging area with git add ., which prepares changes for inclusion in a commit. A commit is created using git commit -m "message", capturing a snapshot of the staged changes along with a descriptive message. The git status command is used regularly to view the current state of files in the repository.

Working with Remote Repositories

Remote repositories enable collaboration by allowing developers to share code through platforms such as GitHub. The git clone command creates a local copy of an existing remote repository. Once changes are made locally, they can be uploaded to the remote repository using git push. To retrieve updates made by others, the git pull command is used, which fetches and merges changes into the local branch.

Branching and Collaboration Basics

Branching allows developers to work on new features or fixes independently without affecting the main codebase. The git branch command lists available branches, while git checkout or git switch is used to move between them. After completing work on a branch, changes can be merged back into the main branch. Through these features, Git and Git Bash provide a structured and efficient approach to version control and team collaboration.


Getting Started with the Git Workflow

To get started, it's important to know the basics of how Git works. You may choose to do the actual work within a terminal, an app like GitHub Desktop, or through GitHub.com. Below are the basic git terminologies aligned with GitHub usage.

Repository (Repo)

On GitHub, a repository is an online-hosted version of your project. It stores your code, commit history, issues, pull requests, and documentation. Most collaboration happens around the GitHub repository, which acts as the central reference point for all contributors. A local repository is connected to GitHub using a remote named origin.

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

Commit

A commit is a recorded change to the repository. On GitHub, commits are visible in the Commits tab, where collaborators can review what changed and who made the change. Each commit pushed to GitHub becomes part of the shared project history.

git commit -m "Add login validation"
Enter fullscreen mode Exit fullscreen mode

Branch

In GitHub, branches are heavily used to isolate work. The default branch is usually main, which represents production-ready code. Feature development and bug fixes are done in separate branches, which are later merged into main through pull requests.

git branch feature-auth
git switch feature-auth
Enter fullscreen mode Exit fullscreen mode

Push

Pushing sends your local commits to GitHub, making them visible to collaborators. Until you push, your commits exist only on your local machine. This step is essential for teamwork and backup.

git push origin feature-auth
Enter fullscreen mode Exit fullscreen mode

Pull

Pulling retrieves updates from GitHub and merges them into your local branch. This ensures you are working with the latest version of the project, especially when multiple contributors are involved.

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Pull Request (PR)

A pull request is a GitHub feature used to propose merging one branch into another, usually into main. It allows team members to review code, leave comments, request changes, and approve work before it becomes part of the main codebase. Pull requests are central to GitHub-based collaboration.

Merge

Merging on GitHub usually happens through a pull request rather than directly via the command line. Once approved, GitHub merges the feature branch into the target branch and records the merge in the project history.

Fork

A fork is a GitHub-specific feature that creates a personal copy of someone else’s repository under your account. Forks are common in open-source projects where contributors do not have direct access to the main repository. Changes made in a fork are submitted back using a pull request.

Collaboration workflow

A typical GitHub collaboration workflow involves cloning the repository, creating a branch, committing changes, pushing the branch to GitHub, opening a pull request, undergoing code review, and merging the changes. GitHub enhances Git by adding visibility, discussion, and project management features around this workflow.


When using GitHub, beginners should always pull before starting work, create one branch per feature or fix, push changes frequently, use pull requests instead of direct merges, and write clear commit messages. This approach keeps the repository clean, traceable, and easy to collaborate on.

Top comments (0)