Git Basic Commands: Basic git commands every programmer should know

Here are some basic Git commands with illustrative examples:

1. git init

Initialize a new Git repository in the current directory.

Example:

git init

2. git clone <repository>

Clone a repository from a remote repository to your local machine.

Example:

git clone https://github.com/user/repository.git

3. git add <file>

Add a file to the staging area to prepare for committing.

Example:

git add myfile.txt

4. git commit -m "<message>"

Create a new commit with a <message> to record changes in the staging area.

Example:

git commit -m "Add new feature"

5. git status

Display the status of the repository and files, including the status of uncommitted changes.

Example:

git status

6. git log

Display the commit history of the repository, including information about the commits, authors, and timestamps.

Example:

git log

7. git pull

Synchronize and pull changes from a remote repository into your local repository.

Example:

git pull origin main

8. git push

Push changes from your local repository to a remote repository.

Example:

git push origin main

9. git branch

Display the list of branches in the repository and the currently active branch.

Example:

git branch

10. git checkout <branch>

Switch to a different branch in the repository.

Example:

git checkout feature-branch

11. git merge <branch>

Merge changes from a branch into the current branch.

Example:

git merge feature-branch

12. git remote add <name> <url>

Link a local repository with a remote repository by adding a remote.

Example:

git remote add origin https://github.com/user/repository.git

13. git remote -v

Display the list of remotes linked to the local repository.

Example:

git remote -v

14. git reset <file>

Undo uncommitted changes in a specific file.

Example:

git reset myfile.txt

15. git stash

Temporarily stash uncommitted changes to work on a different branch.

Example:

git stash

 

These are just some of the basic Git commands. Git provides many more commands and functionalities for source code management and collaboration.