Skip to content

Latest commit

 

History

History
111 lines (75 loc) · 1.63 KB

File metadata and controls

111 lines (75 loc) · 1.63 KB

git-commands

Basic Git Commands

Initialize Repository

git init

Clone Repository

git clone <repo_url>

Check Status

git status

Add Changes

git add <file>
git add .

Commit Changes

git commit -m "your message"

View History

git log

Branches

git branch <branch_name>
git checkout <branch_name>
git checkout -b <branch_name>

Merge Branches

git checkout main
git merge <branch_name>

Push to Remote

git push origin <branch_name>

Pull from Remote

git pull origin <branch_name>

🔄 Pull Changes with Rebase

Sometimes, when you’re working on a branch, you want to update your local branch with remote changes but keep a clean linear history.

This is where git pull --rebase is useful.

Commands:

# Switch to your branch
git switch <branch_name>

# Pull latest changes from remote and rebase
git pull --rebase origin <branch_name>

⚡ Advanced Commands

Stash changes temporarily

git stash          # Save current changes
git stash pop      # Apply the stashed changes back
git stash list     # See all stashed changes
git stash apply    # Apply changes but keeps them in the list
git stash clear    # deletes all the stash list

Check remote repositories

git remote -v                       # Show remote URLs
git remote add origin <repo_url>    # Add a new remote

Delete a branch

git branch -d <branch_name>                  # Delete local branch
git push origin --delete <branch_name>       # Delete remote branch