
Here are some hacks, tips, and tricks to improve your productivity while using Git and GitHub:
1. Use Aliases for Faster Commands
Hack: Save time with custom shortcuts.
Define aliases for frequently used Git commands:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all"Usage:
git st # Instead of git status
git lg # Beautiful log visualization2. Leverage .gitignore_global
Hack: Avoid cluttering every repository with .gitignore files.
Define global ignore rules for files you never want in version control:
Create a global
.gitignorefile:touch ~/.gitignore_globalAdd common patterns (e.g., OS or IDE-generated files):
*.log *.swp .DS_Store .idea/Set it as the global ignore file:
git config --global core.excludesfile ~/.gitignore_global
3. Work Smarter with Staging
Hack: Use partial staging for better commit hygiene.
Stage only specific changes in a file:
git add -pThis opens an interactive prompt where you can choose which changes to stage.
4. Automate Tasks with Git Hooks
Hack: Automate repetitive tasks like code linting, testing, or formatting.
- Pre-commit hook: Automatically lint code before committing.
- Post-commit hook: Send notifications or trigger builds.
Create a hook in .git/hooks/pre-commit:
#!/bin/sh
npm run lint || exit 1Make it executable:
chmod +x .git/hooks/pre-commit5. Use git cherry-pick for Selective Commits
Hack: Pick specific commits from another branch.
If you need a single commit from another branch:
git cherry-pick <commit_hash>This avoids merging unnecessary changes.
6. Stay Organized with Pull Request Templates
Hack: Standardize PR descriptions.
Create a
.github/pull_request_template.mdfile in your repo.Add a template:
## Description - What does this PR do? ## Changes Made - List major changes. ## Checklist - [ ] Tests added - [ ] Documentation updated
GitHub will auto-load this template when creating a PR.
7. Use GitHub Keyboard Shortcuts
Hack: Navigate GitHub faster.
| Shortcut | Action |
|---|---|
. |
Open web-based VS Code editor |
t |
Search files in the repository |
y |
Copy permalink for the current file |
w |
Switch between PR files and comments |
l |
Label an issue or PR |
8. Squash Commits Before Merging
Hack: Keep commit history clean.
When merging a branch, use:
git merge --squash <branch_name>This combines all commits into one before merging, making your history easier to read.
9. Use Fork Syncing
Hack: Keep your fork updated with the original repo.
Add the upstream repository:
git remote add upstream <original_repo_url>Sync your fork:
git fetch upstream git merge upstream/main
10. Save Time with git reflog
Hack: Recover from mistakes.
Use git reflog to view all actions performed, even after resets:
git reflogYou can use it to recover lost commits:
git reset --hard <commit_hash>11. Automate Versioning with Tags
Hack: Use semantic versioning to organize releases.
Tag your commits:
git tag -a v1.0.0 -m "Initial release"
git push origin --tagsThis makes it easier to reference versions in GitHub.
12. Batch Manage Issues with GitHub Projects
Hack: Use GitHub Projects for task tracking.
- Group issues into Kanban boards (e.g., To Do, In Progress, Done).
- Use automation rules to move cards between stages.
13. Use git bisect for Debugging
Hack: Pinpoint bugs with binary search.
Start bisect:
git bisect start git bisect bad # Mark the current commit as bad git bisect good <hash> # Mark a known good commitTest each commit; Git will guide you:
git bisect good/badEnd the process:
git bisect reset
14. Visualize Logs with Graphs
Hack: Use a graphical view to track changes.
git log --oneline --graph --decorate --all15. Combine Commands in .bashrc or .zshrc
Hack: Add aliases for frequent tasks in your shell configuration file.
Example:
alias gpush="git push origin $(git branch --show-current)"
alias gpr="gh pr create"Run source ~/.bashrc to activate.
16. Integrate CI/CD with GitHub Actions
Hack: Automate builds, tests, and deployments.
Create a workflow file in
.github/workflows/ci.yml:name: CI Pipeline on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Run Tests run: npm testGitHub will run the workflow automatically for every push to
main.
By using these hacks and tricks, you can dramatically improve your efficiency while working with Git and GitHub. Let me know if you'd like any of these steps expanded further!
