Git Commands

Overview

  • Time: 20 min

  1. Learn how to use Git for version control.

  2. Understand basic Git commands.

Git is a version control system that allows you to track changes in your code and collaborate with others. Here are some basic Git commands:

Basic Git Commands

Command

Description

git init

Initialize a new Git repository.

git add <file>

Stage changes for commit.

git commit -m "message"

Commit staged changes with a message.

git status

Show the status of the working directory and staging area.

git clone <repository-url>

Clone an existing repository.

git push

Push changes to a remote repository.

git pull

Fetch and merge changes from a remote repository.

git branch

List, create, or delete branches.

git checkout <branch>

Switch to a different branch.

git log

Show the commit history of the repository.

Key Points

  • Git is a powerful tool for version control and collaboration.

  • Always commit your changes with clear messages.

  • Use branches to work on features or fixes independently.

  • Regularly push your changes to a remote repository to keep your work backed up and share it with others.