Skip to main content
TellaDev

34 entries

Git

Essential Git commands for version control workflows

34 commands

git init
Initialize a new Git repository
git init my-project
git clone <url>
Clone a remote repository
git clone https://github.com/user/repo.git
git config --global user.name "Name"
Set your name for commits
git config --global user.name "Jane"
git config --global user.email "email"
Set your email for commits
git config --global user.email "[email protected]"
git branch
List all local branches
git branch
git branch <name>
Create a new branch
git branch feature/login
git checkout <branch>
Switch to a branch
git checkout main
git checkout -b <name>
Create and switch to a new branch
git checkout -b feature/login
git merge <branch>
Merge a branch into current branch
git merge feature/login
git branch -d <name>
Delete a branch
git branch -d feature/login
git rebase <branch>
Rebase current branch onto another
git rebase main
git add <file>
Stage a file for commit
git add index.html
git add .
Stage all changes
git add .
git status
Show working tree status
git status
git diff
Show unstaged changes
git diff src/app.ts
git diff --staged
Show staged changes
git diff --staged
git commit -m "message"
Commit staged changes with a message
git commit -m "fix: resolve null check"
git commit --amend
Amend the last commit
git commit --amend
git push
Push commits to remote
git push origin main
git push -u origin <branch>
Push and set upstream branch
git push -u origin feature/login
git pull
Fetch and merge from remote
git pull origin main
git fetch
Download objects from remote without merging
git fetch --all
git remote -v
Show remote URLs
git remote -v
git stash
Stash current changes
git stash
git stash pop
Apply and remove latest stash
git stash pop
git stash list
List all stashes
git stash list
git stash drop
Delete latest stash
git stash drop stash@{0}
git reset HEAD <file>
Unstage a file
git reset HEAD src/app.ts
git reset --soft HEAD~1
Undo last commit, keep changes staged
git reset --soft HEAD~1
git reset --hard HEAD~1
Undo last commit and discard changes
git reset --hard HEAD~1
git revert <commit>
Create a new commit that undoes a previous commit
git revert a1b2c3d
git log --oneline
Show compact commit log
git log --oneline -10
git log --graph --oneline
Show commit log with branch graph
git log --graph --oneline --all
git blame <file>
Show who changed each line of a file
git blame src/app.ts