Post

Basic git commands

Git is a powerful and widely-used version control system that helps developers track changes in their code and collaborate efficiently with others. Here’s a guide to some of the most essential Git commands for beginners to get started.

Setup and Configuration

Before you start using Git, it’s important to configure your identity. This is necessary for proper version control and collaboration.

1
2
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Verify:

1
git config --list

Initializing a Repository

1
git init

This creates a hidden .git folder which contains all the data Git needs to track changes

Cloning a Repository

1
git clone <repository_url>

Checking Repository Status

The git status command shows the current state of your working directory and staging area, displaying changes that are staged, unstaged, or untracked

1
git status

Staging Changes

1
2
3
git add <file_name>

git add .

Committing Changes

1
git commit -m "commit message"

Viewing Commit History

1
git log

Branching

Branches allow you to work on new features or experiments without affecting the main project. To create and switch to a new branch:

1
git checkout -b <branch_name>

You can also switch between branches using

1
git checkout <branch_name>

You can also switch between branches using

1
git branch

Merging Branches

1
2
git checkout main
git merge <branch_name>

Pushing Changes to a Remote Repository

1
git push origin <branch_name>

Pulling Updates from a Remote Repository

1
git pull
This post is licensed under CC BY 4.0 by the author.