Answering the most common GitHub beginner questions

By GitHub

Share:

Key Concepts

  • SSH (Secure Shell): A cryptographic network protocol for secure communication between a computer and GitHub.
  • PAT (Personal Access Token): A credential used to authenticate with GitHub for command-line or API operations.
  • Merging vs. Rebasing: Two methods for integrating changes from one branch into another.
  • Merge Conflict: A state where Git cannot automatically reconcile differences in code between two branches.
  • Forking: Creating a personal copy of a repository to contribute to projects without affecting the original.
  • Pull Request (PR): A mechanism for developers to notify team members about changes pushed to a branch.

1. SSH Key Authentication

SSH keys consist of a private key (stored locally, never shared) and a public key (uploaded to GitHub).

  • Generation: Run ssh-keygen -t ed25519 -c "[email protected]" in the terminal. Accept defaults and set a passphrase.
  • SSH Agent: A program that stores keys to avoid repeated passphrase entry. Add the key using ssh-add ~/.ssh/id_ed25519.
  • Setup: Copy the public key using cat ~/.ssh/id_ed25519.pub, navigate to GitHub Settings > SSH and GPG keys, and click New SSH key.

2. Personal Access Tokens (PATs)

PATs are used for authentication when Git asks for a password.

  • Creation: Go to Settings > Developer settings > Personal access tokens.
  • Fine-grained vs. Classic: Fine-grained tokens offer granular permissions (scopes) and repository-specific access. Classic tokens are broader and often used for general repository operations.
  • Process: Name the token, set an expiration date, select repository access, and define permissions (e.g., read/write for issues or workflows). Copy the token immediately, as it will not be shown again.

3. Merging vs. Rebasing

  • Merging: Combines branches by creating a new "merge commit." It preserves the full history of both branches. Best for feature branches entering the main branch.
  • Rebasing: Moves or "replays" local commits on top of another branch. It creates a linear, clean history. Best for updating a feature branch with the latest changes from main.
  • Resolving Conflicts: If a conflict occurs, use the GitHub UI to edit the file, remove conflict markers, click Mark as resolved, and then Commit merge.

4. Undoing Commits

  • Pushed Commits: Use the Revert button in the GitHub UI. This creates a new commit that negates the changes, preserving history safely.
  • Local (Unpushed) Commits:
    • git reset --soft HEAD~1: Removes the commit but keeps changes staged.
    • git reset --hard HEAD~1: Removes the commit and discards all changes.

5. Forking and Syncing

  • Forking: Click the Fork button on a repository to create a copy under your account.
  • Syncing (UI): Use the Sync fork menu and select Update branch.
  • Syncing (CLI):
    1. Add upstream: git remote add upstream <original_repo_url>
    2. Fetch: git fetch upstream
    3. Merge: git merge upstream/main
    4. Push: git push

6. Pull Request (PR) Review Best Practices

  1. Understand the Goal: Read the PR description and linked issues.
  2. Review in Sections: Comment on specific lines. Use "nit" for non-blocking suggestions.
  3. Provide Positive Feedback: Highlight well-organized or thoughtful code.
  4. Copilot Code Review: If enabled by an admin, select "Copilot" in the reviewers menu. Note: Copilot reviews are for feedback and do not count toward required approvals for merging.

Synthesis

This guide provides a technical foundation for managing GitHub workflows. The core takeaway is the importance of secure authentication (SSH/PATs), maintaining a clean project history through strategic use of merging and rebasing, and fostering collaborative development through structured PR reviews and proper fork synchronization. Always prioritize security by keeping private keys local and using password managers for tokens.

Chat with this Video

AI-Powered

Load the transcript when you're ready to chat so the initial page stays lighter.

Ready to summarize another video?

Summarize YouTube Video