Here are ten useful Git commands along with examples:

  1. git init: Initializes a new Git repository in the current directory.

    git init
    
  2. git clone: Creates a local copy of a remote repository.

    git clone <repository_url>
    
  3. git add: Adds file(s) to the staging area for the next commit.

    git add <file1> <file2>
  4. git commit: Records changes to the repository with a commit message.

    git commit -m "Commit message"
    
  5. git status: Shows the status of the working directory and staging area.

    git status
    
  6. git pull: Fetches changes from a remote repository and merges them into the current branch.

    git pull origin <branch_name>
    
  7. git push: Pushes local changes to a remote repository.

    git push origin <branch_name>
    
  8. git branch: Lists existing branches or creates a new branch.

    git branch
    git branch <branch_name>
    

     

  9. git checkout: Switches to a different branch or restores files from a previous commit.
    git checkout <branch_name>
    git checkout <commit_hash> <file1> <file2>
    
  10. git log: Shows a history of commits in the repository.

    git log
    

These commands cover some fundamental Git operations, but Git provides a wide range of commands and options for managing version control. It's recommended to explore the Git documentation and other resources to delve deeper into Git's capabilities and command usage.