Skip to content

Instantly share code, notes, and snippets.

@semick-dev
Last active July 10, 2024 18:40
Show Gist options
  • Save semick-dev/719ded1144fac4a48e60f51005c99abc to your computer and use it in GitHub Desktop.
Save semick-dev/719ded1144fac4a48e60f51005c99abc to your computer and use it in GitHub Desktop.
Github Cheatsheet

Git -- CLI, Hub CLI, Hub Site

UI Secrets

  • t to find a file by name
  • s to search
  • Use commenter:<blah> to find every issue that <blah> commented on.

Git CLI

Cloning

Clone with classic gh token

git clone https://@github.com/username/repo.git

Clone with fine grained github tokens

git clone https://oauth2:@github.com/username/repo.git

Tags

Listing a Tag

git tag
git show <tagname> 
git tag <tagname> <commithash>

Push Local

After creating a tag using command above.

git push --tags # for everything
git push <tagname>

Deletion, 'delete a tag', 'deleting a tag'

git tag -d <tag>
git push origin :refs/tags/<tag>
git push --delete origin <tag>

Pruning tags to match remote

git fetch --prune origin "+refs/tags/*:refs/tags/*"
# delete all tags that start with test_ both locally and on remote
git fetch --prune origin "+refs/tags/*:refs/tags/*" && git tag --list | ? { $_.StartsWith("test_") } | % { git push origin --delete $_ }

Create Annotated Tag

git tag -a annotated-azure-template_0.0.1 -m "this is an annotated tag" git push origin :refs/tags/annotated-azure-template_0.0.1

Skipping CI on Commit

Reference

This is supported for commits to Azure Repos Git, Bitbucket Cloud, GitHub, and GitHub Enterprise Server.

[skip ci] or [ci skip]
skip-checks: true or skip-checks:true
[skip azurepipelines] or [azurepipelines skip]
[skip azpipelines] or [azpipelines skip]
[skip azp] or [azp skip]
***NO_CI***

How to checkout PR branch

git fetch origin pull/$ID/head:$BRANCHNAME
git checkout $BRANCHNAME

A few notes on git mv

Moving files up the tree goes "wonky" on Windows machines. Recommendation is to use git bash.

Note: remember that drives don't show up properly on git bash. cd / && ls won't show the disks. Just access the disk as a root folder. EG: C:/repo/sdk-tools turns into /c/repo/sdk-tools.

Furthermore, you will need to remember to add a target . in the suffix of the target path. EG:

# pwd -> /c/repo/sdk-tools/packages/python-packages
# move all files _below_ target folder under another target folder
git mv ./api-stub-generator/* ./apiview-stub-generator/.

403 / Auth errors

If you attempt to push, and are getting issues with

This token is not configured for SSO

Or related issues like that, you probably need to try doing git config --global credential.helper manager-core to force it to actually work with SAML SSO.

SSH

Reference git-ssh.md. Or the gist.

Github CLI (gh)

Github REST API

Authorization using PAT

$headers = @{
    "Accept" = "application/vnd.github+json"
    "Authorization" = "token $gh_token"
}

Invoke-RestMethod -Method GET -Uri "https://api.github.com/repos/azure/azure-sdk-assets-integration" -H $headers

This will work because the powershell Invoke-RestMethod will set the default User-Agent header FOR YOU. Github will reject any API requests that do not specify a User-Agent with a 403 Forbidden. They don't mandate any specific one, just that one is provided.

await octokit.request('GET /repos/{owner}/{repo}/releases', { owner: 'octocat', repo: 'hello-world' })

@{ Authorization="Bearer $key"}

curl
-H "Accept: application/vnd.github.v3+json"
https://api.github.com/repos/octocat/hello-world/releases

curl -i -u https://api.github.com/sbeddall/locker/releases -H "Authorization: token $gh_token"

curl -H "Authorization: token $gh_token" -i https://api.github.com/sbeddall/locker/releases

$headers = @{ "Content-Type" = "application/json" "Authorization" = "token $gh_token" }

#auth #rest #gitapi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment