Git Commands

Git, a distributed version control system, is a fundamental tool in modern software development. Understanding essential Git commands is crucial for effective collaboration, version control, and project management. We'll provide a brief overview of key Git commands that every developer should be familiar with.

1. git init:

Initialize a new Git repository in the current directory:

bash
git init

This creates a new Git repository with the necessary data structures.

2. git clone:

Clone a remote repository to your local machine:

bash
git clone <repository-url>

Replace <repository-url> with the URL of the Git repository you want to clone.

3. git add:

Add changes to the staging area in preparation for a commit:

bash
git add <file>

Replace <file> with the name of the file or use . to add all changes.

4. git commit:

Commit changes with a descriptive message:

bash
git commit -m "Your commit message"

This saves staged changes to the local repository.

5. git status:

Check the status of your working directory:

bash
git status

This displays information about modified, staged, and untracked files.

6. git log:

View the commit history:

bash
git log

This shows a chronological log of commits, including commit messages and authors.

7. git branch:

Create, list, or delete branches:

bash
git branch <branch-name>

Create a new branch with the specified name.

bash
git branch -a

List all branches, including remote branches.

8. git checkout:

Switch branches or restore working tree files:

bash
git checkout <branch-name>

Switch to the specified branch.

bash
git checkout -b <new-branch-name>

Create and switch to a new branch.

9. git merge:

Merge changes from one branch into another:

bash
git merge <branch-name>

This combines changes from the specified branch into the current branch.

10. git pull:

Fetch and integrate changes from a remote repository:

bash
git pull origin <branch-name>

Update your local branch with changes from the remote repository.

11. git push:

Push local changes to a remote repository:

bash
git push origin <branch-name>

This sends your committed changes to the specified branch on the remote repository.

12. git remote:

Manage remote repositories:

bash
git remote -v

List all remote repositories and their URLs.

bash
git remote add <remote-name> <repository-url>

Add a new remote repository with the specified name and URL.