Git commands
Git Shortcuts Cheat Sheet with Examples
Create & Clone ▼
Create new repository: git init
Example:
This initializes a new Git repository in the "my-project" folder.
git init my-project
This initializes a new Git repository in the "my-project" folder.
Clone local repository: git clone /path/to/repository
Example:
This clones a local repository located at "/home/user/my-project."
git clone /home/user/my-project
This clones a local repository located at "/home/user/my-project."
Clone remote repository: git clone username@host:/path/to/repository
Example:
This clones a remote repository from GitHub.
git clone user@github.com:user/repo.git
This clones a remote repository from GitHub.
Add & Remove ▼
Add changes to INDEX: git add ‹filename›
Example:
This stages the "index.html" file for commit.
git add index.html
This stages the "index.html" file for commit.
Add all changes: git add *
Example:
This stages all modified and new files for commit.
git add *
This stages all modified and new files for commit.
Remove file: git rm ‹filename›
Example:
This removes "old-file.txt" from the repository.
git rm old-file.txt
This removes "old-file.txt" from the repository.
Commit & Synchronize ▼
Commit changes: git commit -m "Commit message"
Example:
This commits the staged changes with the message "Added new features."
git commit -m "Added new features"
This commits the staged changes with the message "Added new features."
Push changes: git push origin master
Example:
This pushes changes to the "main" branch of the remote repository.
git push origin main
This pushes changes to the "main" branch of the remote repository.
Branches ▼
Create new branch: git checkout -b ‹branch›
Example:
This creates a new branch "feature-login" and switches to it.
git checkout -b feature-login
This creates a new branch "feature-login" and switches to it.
Switch to master: git checkout master
Example:
This switches to the "main" branch.
git checkout main
This switches to the "main" branch.
Comments
Post a Comment