Introduction to GIT

Mayank JoshiMayank Joshi
3 min read

Version Control

Version control is a tool that helps you keep track of changes in your code over time. Think of it like a shared document where multiple people can work together, make edits, and still be able to go back to earlier versions if needed. It’s especially useful when working in a team, as it helps manage updates, avoid conflicts, and keep everything organized. In the long run, it makes the development process smoother and more efficient.

Git

Git is a distributed version control system that's completely free and open-source. It’s used to track changes in files and manage project history, especially when multiple people are contributing to the same codebase.

Repository

A repository is basically a folder that stores all your project files and their version history which are called commits.

Commits

A commit is like a save point that captures the current state of your project. Each commit has a unique ID and you can look back at previous commits to see what changes were made and when.

Branches

Branches let you work on different features or big-fixes separately without affecting the main code. Eventually, changes from a branch can be merged back into the main branch.

How to setup Git for you linux/windows device

On Linux - Ubuntu/Mint/Debian

# Install Git using these commands
sudo apt update
sudo apt install git

On Windows -

Download Git from - https://git-scm.com/downloads/win
Run the installer.

Verify git installation -

git --version

Configure your Git -

# open you bash or terminal and run the following commands
git config --global user.name "Your Name"
git config --global user.email "Your email"

Git commands you should know

# Initialize a new Git repository
git init

# Clone a remote repository to your local machine
git clone <repo-url>

# Check the current status of your files
git status

# Add a specific file to the staging area
git add <filename>

# Add all changes to the staging area
git add .

# Commit the staged changes with a message
git commit -m "Your commit message here"

# View the commit history
git log

# List all local branches
git branch

# Create a new branch
git branch <branch-name>

# Switch to an existing branch
git checkout <branch-name>

# Create and switch to a new branch in one command
git checkout -b <new-branch-name>

# Merge a branch into the current branch
git merge <branch-name>

# Downloads latest changes but without merging them into the current branch
git fetch

# Fetch and merge changes from the remote repo
git pull

# Push your commits to the remote repo
git push

Common things to remember while working with Git

  • Commit often and push it to your remote branch.

  • Write clear commit messages.

  • Do not push directly to the main branch.

  • Use branches for features or bug-fix.

0
Subscribe to my newsletter

Read articles from Mayank Joshi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mayank Joshi
Mayank Joshi