Skip to content

Instantly share code, notes, and snippets.

@stevemar
Last active Jun 21, 2021
Embed
What would you like to do?
git cheatsheet

GitHub Enterprise

Clone all GHE repos

This is limited to cloning 100 repos at a time, the second command gets page 2

TOKEN=foo
ORG_NAME=developer-journey
COMPANY=IBM

$ curl -s "https://github.ibm.com/api/v3/orgs/developer-journeys/repos?access_token=TOKEN&per_page=100" | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}' 
$ curl -s "https://github.ibm.com/api/v3/orgs/developer-journeys/repos?access_token=TOKEN&per_page=100&page=2" | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}' 

Move a repo from GHE to GH

This will keep the commit history!

## get the repo to be cloned
$ git clone git@github.ibm.com:IBMDigital/Procurement-System.git
## rename the origin branch to something else to avoid conflicts
$ git remote rename origin destination
## go to github and create an empty repo, add the new repo location
$ git remote add origin https://github.com/IBM/procurement-system.git
## optionally check remotes using -v
$ git remote -v
destination	git@github.ibm.com:IBMDigital/Procurement-System.git (fetch)
destination	git@github.ibm.com:IBMDigital/Procurement-System.git (push)
origin	https://github.com/IBM/procurement-system.git (fetch)
origin	https://github.com/IBM/procurement-system.git (push)
## push code up to new remote branch
$ git push -u origin master
## note that if using the below command with 2FA, you will need to
## use a personal access token as a password along with your username!

Gerrit

Remote Rebasing

  1. Click "Rebase" button in the Gerrit UI under your patch set.

Local rebasing

  1. git review -d $PARENT_CHANGE_NUMBER
  2. git review -x $BROKEN_CHANGE_NUMBER
  3. fix the issues
  4. git add
  5. git cherry-pick --continue
  6. git review

backporting a patch

  1. git checkout -b some_branch_name origin/stable/liberty
  2. git review -x <patch #>
  3. fix errors
  4. git add keystone/
  5. git cherry-pick --continue
  6. modify the commit message
  7. git review stable/liberty

General Git

Undo a git commit amend

  1. git reflog (to find the number)
  2. git reset --soft HEAD@{number}
  3. git commit -C HEAD@{number}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment