Here are ten useful Git commands along with examples:
git init: Initializes a new Git repository in the current directory.
git clone: Creates a local copy of a remote repository.
git clone <repository_url>
git add: Adds file(s) to the staging area for the next commit.
git add <file1> <file2>
git commit: Records changes to the repository with a commit message.
git commit -m "Commit message"
git status: Shows the status of the working directory and staging area.
git pull: Fetches changes from a remote repository and merges them into the current branch.
git pull origin <branch_name>
git push: Pushes local changes to a remote repository.
git push origin <branch_name>
git branch: Lists existing branches or creates a new branch.
git branch git branch <branch_name>
- git checkout: Switches to a different branch or restores files from a previous commit.
git checkout <branch_name> git checkout <commit_hash> <file1> <file2>
git log: Shows a history of commits in the repository.
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.