github tricks

February 14, 2025

Include only selected files in a pull request

A pull request proposes changes from a head branch into a base branch; it does not provide a separate file-selection step to determine what will be merged. To limit a pull request to specific files, create a branch from the intended base and commit only the relevant changes on that branch.

If an existing branch already contains unrelated changes, adding a new commit does not remove them from the pull request. Prepare a separate branch containing only the intended changes before opening the pull request.

Reference: GitHub pull request documentation.

Mention an open issue in a PR comment

To reference an issue in a pull request comment, use # followed by the issue number (e.g., #123). As you type #, GitHub will suggest matching issues and PRs from the repository to choose from.

Github pull request shows wrong diff

I encountered this when I have squash merged the changes from main to feature and then try to pull feature to main then the changes in the suqash merge are listed as different(but at this time file contents are identical two branch).

reason

https://stackoverflow.com/questions/55479729/github-pull-request-shows-wrong-diff Despite the misleading/broken github interface there's actually a way to get what you want. You need to drop one .

Instead of:

https://github.com/account/repo/compare/branchA...branchB

do

https://github.com/account/repo/compare/branchA..branchB

This compares branch heads instead of simply using the base branch to find the merge base.

github's reponse is what clued me in from @edwin-evans' response:

This is a result of the type of diff we use on GitHub. We use git’s three dot diff, which is the difference between the latest commit on the HEAD branch and the last common ancestor commit with the base branch.

I asked this of Github Support and here is their official answer:

We show what's called a "three-dot diff" which is the difference between the latest commit on the HEAD branch and the last common ancestor commit with the base branch. So if you forked off of a repo a while ago and things have changed in the parent repo since then, or if you opened a PR from the master branch and then the master branch has changed in the meantime, the diff wouldn't show that.

It sounds like you'd rather see a "two-dot diff", which would show the changes between the two most recent commits on each branch. In future you can merge the base branch back into the head branch. That updates the last common ancestor and would be more likely to show you what you're expecting to see there.

why

because git does not recommand merge and solve conflicts on local before creating pull request on remote branches, its rather good practice to pull and solve conflicts on remote to keep a clean history and a good workflow.

Signed commits and Verified status

Commit signing, SSH authentication, and contribution attribution answer different questions. For the full discussion of GPG and SSH signing, persistent verification after key removal, and email-related contribution issues, see Signing Git Commits on GitHub: GPG, SSH, and Verified Status.

Cite this repository

GitHub allows you to add a "Cite this repository" button in the sidebar by creating a CITATION.cff file in your repo root.

Basic CITATION.cff

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
type: software
title: "Your Project Name"
authors:
  - family-names: "Your"
    given-names: "Name"
    email: "[email protected]"
    orcid: "https://orcid.org/0000-0000-0000-0000"  # optional
version: "1.0.0"
date-released: "2025-01-05"
url: "https://github.com/your-username/your-repo"
repository-code: "https://github.com/your-username/your-repo"
license: MIT
keywords:
  - keyword1
  - keyword2
abstract: "Brief description of your project."

With academic paper citation

If your project has an associated paper, add a preferred-citation block:

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
type: software
title: "Your Project Name"
authors:
  - family-names: "Your"
    given-names: "Name"
preferred-citation:
  type: article
  authors:
    - family-names: "Your"
      given-names: "Name"
  title: "Paper Title"
  journal: "Journal Name"
  year: 2025
  doi: "10.xxxx/xxxxx"

Setup steps

  1. Create CITATION.cff in repo root
  2. Commit and push:
    git add CITATION.cff
    git commit -m "Add citation file"
    git push
  3. Verify: Go to your repo on GitHub → Look for "Cite this repository" in the right sidebar under "About"

GitHub automatically generates BibTeX and APA citations from this file.

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-02-14). github tricks. https://caiborui.com/blog/2025-02-14-en-github-tricks

@misc{borui2025-19108a8a,
  author = {borui},
  title = {{github tricks}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-02-14-en-github-tricks}
}