๐ Day 7 - Advance Git & Github #90DaysOfDevOps ๐
Advanced Git Concepts:
Rebasing:
Rebase: Rewriting commit history by moving all changes from one branch to another.
git checkout feature-branch git rebase main
Interactive Rebase:
Interactive Rebase: Squashing, editing, or reordering commits interactively.
git rebase -i HEAD~3
Stashing:
Stash: Temporarily shelving changes to work on something else.
git stash git stash pop
Cherry-pick:
Cherry-pick: Applying individual commits from one branch to another.
git cherry-pick <commit-hash>
Git Hooks:
Hooks: Custom scripts triggered by Git events like commit, push, etc.
.git/hooks/
Submodules:
Submodules: Incorporating other repositories into your project.
git submodule add <repository_url>
Advanced GitHub Usage:
Branch Protection:
Branch Protection: Prevent force pushes or direct commits to important branches.
- Configure in repository settings on GitHub.
GitHub Actions:
GitHub Actions: Automated workflows triggered by GitHub events.
- Create workflows in
.github/workflows/
.
- Create workflows in
GitHub Packages:
GitHub Packages: Host and manage packages within GitHub.
- Publish and consume packages using
npm
,pip
,docker
, etc.
- Publish and consume packages using
GitHub CLI:
GitHub CLI: Command-line interface for GitHub operations.
- Install and authenticate using
gh
.
- Install and authenticate using
Code Reviews:
Code Reviews: Effective collaboration through thorough code reviews.
- Utilize pull requests, comments, and reviews on GitHub.
Project Boards:
Project Boards: Manage tasks and workflows using GitHub's project boards.
- Organize tasks into columns (To do, In progress, Done).
Example:
Rebasing Workflow:
Start a feature branch:
git checkout -b feature-branch
Make commits to the feature branch.
Rebase changes onto the main branch:
git rebase main
Resolve conflicts if any.
Continue working or push changes:
git push origin feature-branch
GitHub Actions:
Create a workflow file in
.github/workflows/
directory.Define triggers and actions.
Example workflow to run tests on push:
name: Run Tests on: [push] jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Install dependencies run: npm install - name: Run tests run: npm test
Branch Protection:
Go to repository settings on GitHub.
Select "Branches" and add branch protection rules for
main
branch.Require pull request reviews before merging.
Disallow force pushes.
Subscribe to my newsletter
Read articles from Umesh Sangule directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by