- Cloning with a Token
- Branch Management
- Committing & Pushing
- Updating Strategies
- Undoing Changes
- Essential Tools
- GitHub.com → Settings → Developer Settings → Personal Access Tokens (classic)
- Select
repoandworkflowscopes - Never store tokens in code
# Interactive (safer)
git clone https://github.com/username/repo.git
# When prompted: username = GitHub username, password = PASTE_TOKEN
# Embedded token (temporary use only)
git clone https://<TOKEN>@github.com/username/repo.git# Create and switch to new branch
git checkout -b feature/new-login
# Push branch to remote & set upstream
git push -u origin feature/new-login
# List all branches (local & remote)
git branch -a
# Delete merged remote branch
git push origin --delete old-branch- Stage changes:
git add . # All files
git add src/component.js # Specific file- Commit with message:
git commit -m "Add user login validation"- Push to remote:
git push origin main # Push to specific branch
git push # Push to tracked branch- Atomic Commits: Commit small logical changes instead of bulk updates
- Meaningful Messages: Use imperative tense ("Fix bug" not "Fixed bug")
- Push Frequency: Push daily to avoid merge conflicts
| Scenario | Command |
|---|---|
| Discard local changes | git reset --hard origin/main |
| Save changes temporarily | git stash → pull → stash pop |
| Clean history | git pull --rebase |
| Safe merge | Commit first, then git pull |
git reset HEAD src/component.jsgit checkout -- src/component.js # Single file
git reset --hard HEAD # All changesgit commit --amend # Change message/files
git push --force # ⚠️ Only if not pushed yet!git revert abcd1234 # Creates undo commit
git pushgit status # Changed/untracked files
git log --oneline --graph # Compact commit historygit remote -v # List remotes
git remote set-url origin https://<NEW_URL> # Change remote URLCreate .gitignore file to exclude:
- Node modules (
node_modules/) - Environment files (
.env) - Build artifacts (
dist/,.build/)
git tag v1.0.0 # Create tag
git push origin v1.0.0 # Push tag| Action | Command |
|---|---|
| Commit all changes | git add . && git commit -m "msg" |
| Push new branch | git push -u origin branch-name |
| Pull latest changes | git pull --rebase |
| Compare changes | git diff HEAD^ |
| Clean untracked files | git clean -fd |
"Your branch is ahead of 'origin/main'"
git push # You have unpushed commits"Updates were rejected"
git pull --rebase # Fetch and rebase firstAccidental commit to wrong branch
git reset HEAD~1 # Undo commit
git stash # Save changes
git checkout correct-branch
git stash popRecover deleted branch
git reflog # Find lost commit hash
git checkout -b branch-name <hash>