Git is a version control system I use to track changes in code:
# Main Git commands
git add .
git commit -m "Added new feature"
git push origin main
git pull origin main
git checkout -b feature/new-featureGit is a distributed version control system that allows tracking code changes, working in teams, and managing project versions. 🚀
To start working with Git, you need to either create a new repository or clone an existing one:
# Create a new repository
git init
# Clone an existing repository
git clone https://github.com/username/repository.git
# Configure name and email
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"The daily Git workflow includes these commands:
# Check repository status
git status
# Add files to staging
git add file.txt
git add . # Add all changes
# Create a commit
git commit -m "Brief description of changes"
# Send changes to remote repository
git push origin main
# Get changes from remote repository
git pull origin mainBranches allow developing features in isolation:
# View all branches
git branch
# Create a new branch
git branch feature/new-feature
# Create and switch to a new branch
git checkout -b feature/new-feature
# Switch between branches
git checkout main
# Delete a branch
git branch -d feature/new-featureTo combine changes from different branches, use merge and rebase:
# Merge feature branch into current branch
git merge feature/new-feature
# Rebase current branch onto feature
git rebase feature/new-feature
# Resolve conflicts
# After manually resolving conflicts:
git add .
git merge --continue # or git rebase --continueFor analyzing change history:
# View commit history
git log
# Compact history view
git log --oneline
# Graphical history representation
git log --graph --oneline --all
# View changes in specific commit
git show <commit-hash>Stash allows temporarily saving unfinished changes:
# Save current changes
git stash
# Apply saved changes
git stash apply
# Apply and remove from stash
git stash pop
# View stash list
git stash listFor fixing mistakes:
# Discard changes in working directory
git checkout -- file.txt
# Unstage a file
git reset HEAD file.txt
# Modify the last commit
git commit --amend
# Undo last commit (keeping changes)
git reset --soft HEAD~1
# Completely undo last commit
git reset --hard HEAD~1For synchronizing with remote repositories:
# View remote repositories
git remote -v
# Add a remote repository
git remote add origin https://github.com/username/repository.git
# Fetch changes without merging
git fetch origin
# Fetch and merge changes
git pull origin main# Create branch for new feature
git checkout -b feature/user-authentication
# Development and commits
git add .
git commit -m "Added login form"
git add .
git commit -m "Added password validation"
# Sync with main branch
git checkout main
git pull origin main
git checkout feature/user-authentication
git rebase main
# Push branch to remote repository
git push origin feature/user-authentication
# After code review and approval
git checkout main
git merge feature/user-authentication
git push origin main# Create hotfix branch from main
git checkout main
git checkout -b hotfix/critical-bug
# Fix the bug
git add .
git commit -m "Fixed critical bug"
# Push the fix
git push origin hotfix/critical-bug
# Apply fix to main
git checkout main
git merge hotfix/critical-bug
git push origin main❌ Wrong:
# Commit all changes without review
git add .
git commit -m "Changes"✅ Right:
# Review changes before commit
git status
git diff
git add file1.js file2.js
git commit -m "Added form validation and error handling"Git is a powerful tool for code version management:
Use Git for effective teamwork and project history management! 🚀