git

🏠 Homepage

⬅️ Previous: 🌐 Connecting local repo to GitHub using SSH & Push to origin

10. πŸ“‹ Summary

πŸš€ Initialize & Push First Repo (Summary)

echo "# my-first-repo" >> README.md     # Create a README
git init                                # Initialize Git repo
git add README.md                       # Stage the README
git commit -m "first commit"            # Commit it
git branch -M main                      # Rename branch to main
git remote add origin git@github.com:samyak-shrestha/my-first-repo.git  # Link to GitHub
git push -u origin main                 # Push to GitHub

πŸ” Repeated Git Workflow (Save & Push Changes)

git add .                             # Stage all changes
git commit -m "commit message"        # Commit with a message
git push origin branch-name           # Push to the correct branch

πŸ“˜ Basic Git & Bash Commands (Cheat Sheet)


🧰 Git Commands

| Command | Description | |——–|β€”β€”β€”β€”-| | git status | Show current status (what’s staged, unstaged, untracked) | | git add filename | Stage a specific file | | git add . | Stage all changes in current directory | | git commit -m "message" | Commit staged files with a message | | git push origin branch-name | Push current branch to GitHub | | git log | Show commit history | |git stash | temporarily saves your uncommitted changes so you can work on something else and reapply them later.| β€”

πŸ’» Bash Commands

Command Description
cd foldername Change directory
cd .. Go up one level
ls List files/folders
ls -a List all files including hidden
touch filename Create a new empty file
mkdir foldername Create a new directory
cat filename View file content
rm filename Delete a file
clear Clear terminal screen
pwd Show current directory path

πŸ’‘ Tip: Combine git status and git add/git restore regularly to keep your workflow clean.


πŸ” SSH Setup Summary

# Generate SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"

# Start SSH agent and add key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Copy public key
cat ~/.ssh/id_ed25519.pub

# Test connection
ssh -T git@github.com

➑️ Up Next: πŸ“ Hands-On Exercise