- git init:
- Usage:
git init
- Description: Initializes a new Git repository in the current directory.
- Usage:
- git clone:
- Usage:
git clone <repository-url>
- Description: Creates a local copy of a remote repository on your machine.
- Example:
git clone https://github.com/user/repo.git
- Usage:
- git add:
- Usage:
git add <file>
- Description: Stages changes or new files to be committed.
- Example:
git add index.html
(stages the file “index.html” for commit)
- Usage:
- git commit:
- Usage:
git commit -m "commit message"
- Description: Commits the staged changes, creating a new revision in your repository.
- Example:
git commit -m "Add new feature"
- Usage:
- git push:
- Usage:
git push origin <branch>
- Description: Uploads your committed changes to a remote repository.
- Example:
git push origin main
(pushes committed changes to the “main” branch of the remote repository)
- Usage:
- git pull:
- Usage:
git pull origin <branch>
- Description: Retrieves the latest changes from a remote repository and merges them into your local branch.
- Example:
git pull origin main
(pulls and merges changes from the “main” branch of the remote repository into the current branch)
- Usage:
- git branch:
- Usage:
git branch
- Description: Lists existing branches in your repository.
- Example:
git branch
(displays a list of branches)
- Usage:
- git merge:
- Usage:
git merge <branch>
- Description: Integrates changes from one branch into another.
- Example:
git merge feature-branch
(merges changes from the “feature-branch” into the current branch)
- Usage:
- git status:
- Usage:
git status
- Description: Provides information about the current state of your repository.
- Example:
git status
(displays the status of files, showing modified files, staged changes, etc.)
- Usage:
- git log:
- Usage:
git log
- Description: Displays a chronological list of commits.
- Example:
git log
(displays the commit history)
- Usage:
These examples should give you a good starting point for using Git and navigating basic version control tasks. Remember to adapt the commands and options to your specific repository and workflow.