π Git Mastery & Beautiful Web Development
Master version control and create stunning web experiences
Git Fundamentals
π― What is Git?
Git is a distributed version control system that tracks changes in source code during software development. It allows multiple developers to work on the same project simultaneously without conflicts, making collaboration seamless and efficient.
π Key Git Terminology
Repository (Repo)
A directory containing your project files and Git history
Commit
A snapshot of your code at a specific point in time
Branch
A parallel version of your repository
Merge
Combining changes from different branches
Remote
A version of your repository hosted on a server
Clone
Creating a local copy of a remote repository
Top 50 Git Interview Questions
- Tracking code changes over time
- Enabling collaboration among developers
- Maintaining different versions of code
- Backing up and restoring code
git pull: Downloads changes AND automatically merges them into current branch
Remember: git pull = git fetch + git merge
git rebase: Replays commits from one branch onto another, creating a linear history
Rebase creates cleaner history but merge preserves context
# When conflict occurs:
git status # See conflicted files
# Edit files to resolve conflicts
git add <resolved-files> # Stage resolved files
git commit # Complete the merge
git revert: Creates a new commit that undoes changes from previous commit
Reset rewrites history, revert preserves history
- Working directory (your current files)
- Staging area (files ready to be committed)
- Git directory (.git folder with history)
git branch <branch-name> # Create branch
git checkout <branch-name> # Switch to branch
# Or combine both:
git checkout -b <branch-name> # Create and switch
git add <file> # Stage specific file
git add . # Stage all changes
git reset --soft HEAD~1 # Undo commit, keep changes staged
git reset --mixed HEAD~1 # Undo commit, unstage changes
git reset --hard HEAD~1 # Undo commit, discard changes
git fork: Creates a copy of a repository under your GitHub account (server-side operation)
Fork is typically used for contributing to open source projects
git status # Shows working directory status
git log --oneline # Shows commit history
git diff # Shows changes in working directory
- Unique SHA-1 hash identifier
- Author information
- Timestamp
- Commit message
- Reference to parent commit(s)
git branch -d <branch-name> # Delete merged branch
git branch -D <branch-name> # Force delete branch
git push origin --delete <branch> # Delete remote branch
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --list # View current configuration
Gitflow: Uses develop, feature, release, and hotfix branches
GitHub Flow: Simple workflow with main branch and feature branches
GitLab Flow: Combines feature-driven development with issue tracking
git stash # Save current changes
git stash pop # Apply and remove latest stash
git stash list # List all stashes
git stash apply stash@{0} # Apply specific stash
git rebase -i HEAD~3 # Interactive rebase for last 3 commits
# Change 'pick' to 'squash' or 's' for commits to squash
# Edit commit message when prompted
- pre-commit: Runs before each commit
- post-commit: Runs after each commit
- pre-push: Runs before pushing to remote
- post-receive: Runs after receiving pushed commits
git cherry-pick <commit-hash> # Apply single commit
git cherry-pick <hash1> <hash2> # Apply multiple commits
git cherry-pick --no-commit <hash> # Apply without committing
- --soft: Moves HEAD, keeps staging area and working directory unchanged
- --mixed (default): Moves HEAD, resets staging area, keeps working directory
- --hard: Moves HEAD, resets staging area and working directory
git branch -m <old-name> <new-name> # Rename branch
git branch -m <new-name> # Rename current branch
# To rename remote branch:
git push origin --delete <old-name>
git push origin <new-name>
git bisect start # Start bisecting
git bisect bad # Mark current commit as bad
git bisect good <commit> # Mark known good commit
git bisect reset # End bisecting session
git format-patch -1 HEAD # Create patch for last commit
git format-patch HEAD~3 # Create patches for last 3 commits
git apply <patch-file> # Apply patch
git am <patch-file> # Apply patch and commit
git checkout <commit-hash> # Creates detached HEAD
git checkout -b <new-branch> # Create branch from detached HEAD
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.unstage 'reset HEAD --'
- origin: Default name for the remote repository you cloned from
- upstream: Refers to the original repository when you've forked it
git config core.autocrlf true # Windows
git config core.autocrlf input # Mac/Linux
git config core.autocrlf false # No conversion
git reflog # Show reference logs
git reflog show HEAD # Show HEAD movements
git reset --hard HEAD@{2} # Reset to previous state
git rm --cached <file> # Remove from index, keep in working directory
# Add to .gitignore
echo "<file>" >> .gitignore
git add .gitignore
git commit -m "Stop tracking file"
git submodule add <url> <path> # Add submodule
git submodule init # Initialize submodules
git submodule update # Update submodules
git config --global user.signingkey <key-id>
git config --global commit.gpgsign true
git commit -S -m "Signed commit" # Sign specific commit
- git pull: Fetches and merges, creating a merge commit
- git pull --rebase: Fetches and rebases your commits on top, creating linear history
git add -p <file> # Interactively stage parts of file
git add --patch <file> # Same as above
# Options: y (yes), n (no), s (split), e (edit)
git blame <file> # Show line-by-line authorship
git blame -L 10,20 <file> # Blame specific lines
git blame -C <file> # Detect moved/copied lines
- Blob: Stores file content
- Tree: Stores directory structure and references to blobs
- Commit: Points to a tree and contains metadata
- Tag: Points to a commit with additional metadata
git gc # Run garbage collection
git gc --aggressive # More thorough cleanup
git prune # Remove unreachable objects
- resolve: Simple two-head merge using 3-way merge algorithm
- recursive (default): Can handle more than two merge bases
- octopus: For merging more than two branches
- ours: Merge result is always from current branch
- subtree: Modified recursive strategy for subtree merging
Essential Git Commands
π₯ Basic Commands
git init # Initialize repository
git clone <url> # Clone remote repository
git status # Check working directory status
git add <file> # Stage changes
git commit -m "message" # Commit changes
git push origin <branch> # Push to remote
git pull origin <branch> # Pull from remote
πΏ Branching Commands
git branch # List branches
git branch <name> # Create branch
git checkout <branch> # Switch branch
git checkout -b <branch> # Create and switch to branch
git merge <branch> # Merge branch
git branch -d <branch> # Delete branch
π Advanced Commands
git log --oneline # View commit history
git diff # Show changes
git stash # Temporarily save changes
git stash pop # Apply stashed changes
git cherry-pick <commit> # Apply specific commit
git bisect # Find bug-introducing commit
Beautiful CSS Techniques
✨ Modern CSS Grid Layout
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
padding: 2rem;
}
.grid-item {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 12px;
padding: 2rem;
transition: transform 0.3s ease;
}
.grid-item:hover {
transform: translateY(-5px);
box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
π Stunning Button Animations
.btn-beautiful {
background: linear-gradient(45deg, #ff6b6b, #feca57);
border: none;
border-radius: 50px;
padding: 15px 30px;
color: white;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-beautiful:hover {
transform: scale(1.05);
box-shadow: 0 15px 35px rgba(255,107,107,0.4);
}
π️ CSS Custom Properties
:root {
--primary-color: #3498db;
--secondary-color: #e74c3c;
--accent-color: #f39c12;
--shadow: 0 4px 6px rgba(0,0,0,0.1);
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.card {
background: var(--bg-color);
box-shadow: var(--shadow);
transition: var(--transition);
}
π― Pro Tips for Success
Git Best Practices
- Write meaningful commit messages
- Use branches for features
- Commit often with small changes
- Always use .gitignore
- Pull before pushing
CSS Best Practices
- Use consistent naming conventions
- Mobile-first approach
- Minimize specificity
- Leverage CSS custom properties
- Optimize for performance
No comments:
Post a Comment