Git commands

Git Shortcuts with Examples

Git Shortcuts Cheat Sheet with Examples

Create & Clone

Create new repository: git init

Example: git init my-project
This initializes a new Git repository in the "my-project" folder.

Clone local repository: git clone /path/to/repository

Example: 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: 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: git add index.html
This stages the "index.html" file for commit.

Add all changes: git add *

Example: git add *
This stages all modified and new files for commit.

Remove file: git rm ‹filename›

Example: git rm old-file.txt
This removes "old-file.txt" from the repository.

Commit & Synchronize

Commit changes: git commit -m "Commit message"

Example: git commit -m "Added new features"
This commits the staged changes with the message "Added new features."

Push changes: git push origin master

Example: git push origin main
This pushes changes to the "main" branch of the remote repository.

Branches

Create new branch: git checkout -b ‹branch›

Example: git checkout -b feature-login
This creates a new branch "feature-login" and switches to it.

Switch to master: git checkout master

Example: git checkout main
This switches to the "main" branch.

Comments