Git-GitHub Cheat Sheet
Git-GitHub Cheat Sheet
gh pr create
gh pr list
git help <command> # List open pull requests in the repository.
# Get detailed help for a specific command.
gh issue create
# Create a GitHub issue from the command line.
Repository Management
Submodules &
and Information
Worktrees
git shortlog -s -n
git submodule add <repo-url> <path> # Summarize commits by author.
# Add a submodule.
git describe --tags
git submodule init # Get a readable name for a commit.
# Initialize submodules.
git blame <file>
git submodule update # Show who last modified each line of a file.
# Update submodules.
git grep "search-term"
git worktree add <path> <branch> # Search for a term in the repository.
# Create a new working tree for a branch.
git revert <commit-id1>..<commit-id2>
# Revert a range of commits.
Cleaning Up
git archive --format=zip HEAD -o latest.zip
# Archive the latest commit as a ZIP file.
git clean -f
# Remove untracked files.
git fsck
# Check the object database for integrity.
git clean -fd
# Remove untracked files and directories.
git gc --prune=now
Spoorti Shetty
# Clean up unnecessary files and optimize the local repository.
Best Practices and Common Workflows
Commit Often: Make frequent commits with descriptive messages to maintain a clear project
history.
Branch for Features: Create a new branch for each feature or bug fix to keep changes
organized and separate from the main codebase.
Use Meaningful Commit Messages: Write clear and concise commit messages that explain the
purpose of the changes.
Pull Regularly: Regularly pull changes from the remote repository to stay updated with the
latest changes and minimize merge conflicts.
Resolve Conflicts Promptly: Address merge conflicts as soon as they arise to avoid
complicating the integration process.
Review Pull Requests Thoroughly: Ensure thorough review of pull requests to maintain code
quality and facilitate knowledge sharing.
Tag Releases: Use tags to mark important milestones or releases in the project for easy
reference in the future.
Keep Your Branches Clean: Delete branches that are no longer needed after merging them
into the main branch to keep the repository organized.
Use Git Hooks for Automation: Utilize Git hooks to automate tasks, like running tests before
committing (pre-commit) or checking commit message formats. Hooks can help ensure code
quality and consistency.
Squash Commits Before Merging: Squash commits to combine related work into a single
commit before merging, especially for feature branches. This keeps the project history clean
and manageable.
Avoid Large Commits: Try to keep commits small and focused on a single change or fix. This
makes it easier to understand the history and isolate issues if something goes wrong.
Create Descriptive Branch Names: Use branch naming conventions that describe the
purpose, such as feature/login-form or fix/user-authentication-bug. This improves readability
and collaboration.
Keep the Main Branch Deployable: Always ensure that the main or production branch is
stable and deployable. This allows the project to be released or updated at any time.
Spoorti Shetty