git-cop

a replacement for checkout that works with branch names copied from PRs

“git cop” = “git checkout pr”

Useful on open source work, and teams where individual contributors fork the central repo on GitHub.

In these scenarios when you click on the copy icon by the branch name in GitHub what you get is prefaced with the username and colon. For example a PR from my the downloads branch of my forked repo would show up as masukomi:downloads

When I make a PR and the recepient wants to actually check out my changes locally they can copy that and then, run git cop <paste>

NOTE: in order for this to work you’ll have had to configure a remote with a matching username. git-cop will warn you if you haven’t.

Usage

USAGE: git-cop <branch name>
       NOTE: branch name can be a 'normal' branch name
       OR one of the identifiers you get from GitHub
       when you copy the branch from a PR from a forked repo.
       Those look like <username>:<branch_name>
       In that scenario this presumes that you have already
       checked out their fork as a remote.

       Due to limitations of git, this _will_ fail if the
       same branch name exists in more than one remote.

Metadata:

Tags:

  • git