Learn Git, GitHub, branching strategies, and most used commands.
Git is a distributed version control system that allows developers to track and manage changes in their code over time. It helps in collaboration, backup, and organizing code efficiently.
Example: You can make changes in your code, commit them, and then revert or compare versions easily with Git.
GitHub is a cloud-based platform that hosts Git repositories, enabling collaboration and project management. It allows multiple developers to work on the same project simultaneously.
Example: You can clone a GitHub repository locally, make changes, push them back, and open a pull request for review.
GitHub Actions is a CI/CD (Continuous Integration / Continuous Deployment) service provided by GitHub. It allows you to automate tasks like:
Example Workflow: Every time you push code to the main branch, GitHub Actions can automatically build your project, run tests, and deploy it to GitHub Pages or any cloud platform.
Branching strategies help organize work and manage code changes safely, especially when multiple developers are involved.
Example: You can create a branch feature/login-page
to work on a login feature. Once complete, it can be merged into the main branch safely.
Merge: Combines two branches preserving the full history. Useful when you want to see all commits from both branches.
Rebase: Moves your branch commits on top of another branch for a linear, cleaner history. Useful for keeping history tidy before merging.
Merge | Rebase |
---|---|
Preserves history | Linear history |
Easy to understand | Rewrites history, careful with shared branches |
Example: If your branch is behind main, merging will create a merge commit, while rebasing will move your commits on top of main.
git config --global user.name "Your Name" # Set username globally
git config --global user.email "you@example.com" # Set email globally
git init # Initialize a new repository
git status # Show working directory status
git add file # Stage a specific file
git add . # Stage all changes
git commit -m "msg" # Commit with a message
git log # View commit history
git diff # Show unstaged changes
git show id # Show a specific commit
git rm file # Remove a file
git mv old new # Move or rename a file
git branch # List branches
git branch new # Create new branch
git checkout branch # Switch to branch
git checkout -b branch # Create + switch branch
git merge branch # Merge branch into current
git rebase branch # Reapply commits onto another
git branch -d branch # Delete branch (safe)
git branch -D branch # Force delete branch
git log --oneline --graph # Visualize commit graph
git reflog # Show reference log
git remote -v # Show remotes
git remote add origin url # Add a remote
git clone url # Clone a repo
git fetch # Fetch from remote
git pull # Fetch + merge
git push # Push changes
git push -u origin branch # Push + set upstream
git remote remove name # Remove remote
git remote show name # Show remote info
git push origin --delete branch # Delete remote branch
git stash # Save changes temporarily
git stash list # List stashes
git stash apply # Reapply last stash
git stash drop # Remove last stash
git revert id # Revert a commit
git reset --soft id # Undo, keep changes staged
git reset --hard id # Undo completely
git clean -fd # Remove untracked files
git tag # List tags
git tag name # Create a tag
git show tag # Show tag details
git cherry-pick id # Apply a specific commit
git blame file # Who changed each line
git shortlog # Summarize commits by author
git bisect start # Begin binary search
git bisect bad # Mark commit as bad
git bisect good # Mark commit as good
git describe # Describe commit/tag