Create a gist now

Instantly share code, notes, and snippets.

@stevemart /
Last active Jul 19, 2018

What would you like to do?
my cheatsheet for git commands

GitHub Enterprise

Clone all GHE repos

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


$ curl -s "" | ruby -rubygems -e 'require "json"; JSON.load( { |repo| %x[git clone #{repo["ssh_url"]} ]}' 
$ curl -s "" | ruby -rubygems -e 'require "json"; JSON.load( { |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
## 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
## optionally check remotes using -v
$ git remote -v
destination (fetch)
destination (push)
origin (fetch)
origin (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!


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