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.


git init

2. git clone <repository>

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


git clone

3. git add <file>

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


git add myfile.txt

4. git commit -m "<message>"

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


git commit -m "Add new feature"

5. git status

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


git status

6. git log

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


git log

7. git pull

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


git pull origin main

8. git push

Push changes from your local repository to a remote repository.


git push origin main

9. git branch

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


git branch

10. git checkout <branch>

Switch to a different branch in the repository.


git checkout feature-branch

11. git merge <branch>

Merge changes from a branch into the current branch.


git merge feature-branch

12. git remote add <name> <url>

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


git remote add origin

13. git remote -v

Display the list of remotes linked to the local repository.


git remote -v

14. git reset <file>

Undo uncommitted changes in a specific file.


git reset myfile.txt

15. git stash

Temporarily stash uncommitted changes to work on a different branch.


git stash


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