Skip to main content

Git

Basics

CommandDescription
git init

Initialize a Repository

git clone "<repository-url>"

Clone a Repository

git add --all

Add all to Staging Area

git commit -m "Commit message"

Commit Changes

git push origin "<branch-name>"

Push Changes to Remote Repository

git pull origin "<branch-name>"

Pull Changes from Remote Repository

git switch "<branch-name>"

Switch Branches

git switch -c "<new-branch-name>"

Create and Switch to a New Branch

Branching

CommandDescription
git checkout -b "<branch-name>"

Create a New Branch

git merge "<branch-name>"

Merge Branches

git branch -d "<branch-name>"

Delete a Branch

Monitoring

CommandDescription
git status

View Changes

git log

View Commit History

git checkout --file

Undo Changes in Working Directory

git reset HEAD "<file>"

Undo Staged Changes

git reset HEAD~1 --soft

Undo Last Commit

Collaborating

CommandDescription
git remote add origin "<repo-url>"

Add Remote Repository

git remote -v

List Remote Repositories

git fetch origin

Fetch Changes from Remote Repository

Advanced

CommandDescription
git stash

Stash Changes

git stash apply

Apply Stashed Changes

git rebase "<base-branch>"

Rebase Branch

git commit --amend

Amend Last Commit