Skip to content

Instantly share code, notes, and snippets.

@stevemar
Last active January 23, 2024 19:11
Show Gist options
  • Select an option

  • Save stevemar/06ace005f82691435d0b to your computer and use it in GitHub Desktop.

Select an option

Save stevemar/06ace005f82691435d0b to your computer and use it in GitHub Desktop.

Revisions

  1. stevemar revised this gist May 6, 2020. No changes.
  2. @stevemart stevemart renamed this gist Jul 19, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @stevemart stevemart revised this gist Mar 31, 2018. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions git and gerrit tips and tricks.md
    Original file line number Diff line number Diff line change
    @@ -18,19 +18,22 @@ $ curl -s "https://github.ibm.com/api/v3/orgs/developer-journeys/repos?access_to
    > 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
    ## 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!
    $ git push -u origin master
    ```

    ---
  4. @stevemart stevemart revised this gist Feb 3, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion git and gerrit tips and tricks.md
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,15 @@

    ## 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=200" | 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" | 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
  5. @stevemart stevemart revised this gist Feb 2, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git and gerrit tips and tricks.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,8 @@ 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)
    ## note that if using the below command with 2FA, you will need to use a personal access token as a password!
    ## 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!
    $ git push -u origin master
    ```

  6. @stevemart stevemart revised this gist Feb 2, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git and gerrit tips and tricks.md
    Original file line number Diff line number Diff line change
    @@ -18,13 +18,14 @@ $ curl -s "https://github.ibm.com/api/v3/orgs/developer-journeys/repos?access_to
    $ 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
    $ git remote add origin https://github.com/IBM/procurement-system.git
    $ 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)
    ## note that if using the below command with 2FA, you will need to use a personal access token!
    ## note that if using the below command with 2FA, you will need to use a personal access token as a password!
    $ git push -u origin master
    ```

  7. @stevemart stevemart revised this gist Jan 31, 2018. 1 changed file with 11 additions and 7 deletions.
    18 changes: 11 additions & 7 deletions git and gerrit tips and tricks.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Git
    # GitHub Enterprise

    ## Clone all GHE repos

    @@ -45,12 +45,6 @@ $ git push -u origin master
    1. git cherry-pick --continue
    1. git review

    ## Undo a git commit amend

    1. git reflog (to find the number)
    1. git reset --soft HEAD@{number}
    1. git commit -C HEAD@{number}

    ## backporting a patch

    1. git checkout -b some_branch_name origin/stable/liberty
    @@ -60,3 +54,13 @@ $ git push -u origin master
    1. git cherry-pick --continue
    1. modify the commit message
    1. git review stable/liberty

    ---

    # General Git

    ## Undo a git commit amend

    1. git reflog (to find the number)
    1. git reset --soft HEAD@{number}
    1. git commit -C HEAD@{number}
  8. @stevemart stevemart revised this gist Jan 31, 2018. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions git and gerrit tips and tricks.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    # Git

    ---

    ## Clone all GHE repos

    ```
    @@ -34,8 +32,6 @@ $ git push -u origin master

    # Gerrit

    ---

    ## Remote Rebasing

    1. Click "Rebase" button in the Gerrit UI under your patch set.
  9. @stevemart stevemart revised this gist Jan 31, 2018. 2 changed files with 66 additions and 62 deletions.
    66 changes: 66 additions & 0 deletions git and gerrit tips and tricks.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    # Git

    ---

    ## Clone all GHE repos

    ```
    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=200" | 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!
    ```
    $ 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
    $ git remote add origin https://github.com/IBM/procurement-system.git
    $ 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)
    ## note that if using the below command with 2FA, you will need to use a personal access token!
    $ git push -u origin master
    ```

    ---

    # Gerrit

    ---

    ## Remote Rebasing

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

    ## Local rebasing

    1. git review -d $PARENT_CHANGE_NUMBER
    1. git review -x $BROKEN_CHANGE_NUMBER
    1. fix the issues
    1. git add
    1. git cherry-pick --continue
    1. git review

    ## Undo a git commit amend

    1. git reflog (to find the number)
    1. git reset --soft HEAD@{number}
    1. git commit -C HEAD@{number}

    ## backporting a patch

    1. git checkout -b some_branch_name origin/stable/liberty
    1. git review -x <patch #>
    1. fix errors
    1. git add keystone/
    1. git cherry-pick --continue
    1. modify the commit message
    1. git review stable/liberty
    62 changes: 0 additions & 62 deletions git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -1,62 +0,0 @@
    Remote Rebasing
    ---------------

    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

    Undo a git commit amend
    -----------------------

    1. git reflog (to find the number)
    2. git reset --soft HEAD@{number}
    3. git commit -C HEAD@{number}

    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

    creating a new oslo library
    ---------------------------

    Before starting, create a new repo within your own github account do not set a license or description.
    The following example uses oslo.io, so io is used throughout this doc.

    ::

    cd /tmp
    mkdir graduation
    cd graduation
    git clone git://git.openstack.org/openstack/oslo-incubator
    git clone git://git.openstack.org/openstack/oslo-incubator oslo.io
    cd oslo.io
    ../oslo-incubator/tools/graduate.sh io openstack/common/fileutils.py tests/unit/test_fileutils.py

    # may not be necessary, but they didn't run for me
    # $bindir/apply_cookiecutter.sh $new_lib
    # git add .
    # git commit -m "exported from oslo-incubator by graduate.sh"

    1. Add missing dependencies
    2. Fix broken imports
    3. Make sure the tests run
    4. Make sure pep8 passes
    5 Syncing dependencies from the incubator

    git remote add stevemart https://github.com/stevemart/oslo.io.git
    git push -u stevemart master
  10. @stevemart stevemart revised this gist Apr 13, 2016. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -23,11 +23,13 @@ Undo a git commit amend
    backporting a patch
    -------------------

    1. create a branch
    2. git checkout -b your_branch_name remotes/origin/stable/havana
    3. hack hack hack
    4. commit changes
    5. git review stable/havana
    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

    creating a new oslo library
    ---------------------------
  11. @stevemart stevemart revised this gist Apr 4, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -32,6 +32,9 @@ backporting a patch
    creating a new oslo library
    ---------------------------

    Before starting, create a new repo within your own github account do not set a license or description.
    The following example uses oslo.io, so io is used throughout this doc.

    ::

    cd /tmp
  12. @stevemart stevemart revised this gist Apr 4, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ backporting a patch
    creating a new oslo library
    ---------------------------

    .. code-block: bash
    ::

    cd /tmp
    mkdir graduation
  13. @stevemart stevemart revised this gist Apr 4, 2015. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -28,3 +28,30 @@ backporting a patch
    3. hack hack hack
    4. commit changes
    5. git review stable/havana

    creating a new oslo library
    ---------------------------

    .. code-block: bash
    cd /tmp
    mkdir graduation
    cd graduation
    git clone git://git.openstack.org/openstack/oslo-incubator
    git clone git://git.openstack.org/openstack/oslo-incubator oslo.io
    cd oslo.io
    ../oslo-incubator/tools/graduate.sh io openstack/common/fileutils.py tests/unit/test_fileutils.py
    # may not be necessary, but they didn't run for me
    # $bindir/apply_cookiecutter.sh $new_lib
    # git add .
    # git commit -m "exported from oslo-incubator by graduate.sh"
    1. Add missing dependencies
    2. Fix broken imports
    3. Make sure the tests run
    4. Make sure pep8 passes
    5 Syncing dependencies from the incubator
    git remote add stevemart https://github.com/stevemart/oslo.io.git
    git push -u stevemart master
  14. @stevemart stevemart revised this gist Mar 11, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -26,5 +26,5 @@ backporting a patch
    1. create a branch
    2. git checkout -b your_branch_name remotes/origin/stable/havana
    3. hack hack hack
    4 commit changes
    4. commit changes
    5. git review stable/havana
  15. @stevemart stevemart revised this gist Mar 11, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,6 @@ backporting a patch

    1. create a branch
    2. git checkout -b your_branch_name remotes/origin/stable/havana
    3. # hack hack hack
    4 # commit changes
    3. hack hack hack
    4 commit changes
    5. git review stable/havana
  16. @stevemart stevemart revised this gist Mar 11, 2015. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -19,3 +19,12 @@ Undo a git commit amend
    1. git reflog (to find the number)
    2. git reset --soft HEAD@{number}
    3. git commit -C HEAD@{number}

    backporting a patch
    -------------------

    1. create a branch
    2. git checkout -b your_branch_name remotes/origin/stable/havana
    3. # hack hack hack
    4 # commit changes
    5. git review stable/havana
  17. @stevemart stevemart revised this gist Mar 11, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions git tips and tricks.rst
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,6 @@ Local rebasing
    Undo a git commit amend
    -----------------------

    git reflog (to find the number)
    git reset --soft HEAD@{number}
    git commit -C HEAD@{number}
    1. git reflog (to find the number)
    2. git reset --soft HEAD@{number}
    3. git commit -C HEAD@{number}
  18. @stevemart stevemart renamed this gist Mar 11, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  19. @stevemart stevemart revised this gist Mar 11, 2015. 1 changed file with 13 additions and 12 deletions.
    25 changes: 13 additions & 12 deletions git tips and tricks
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,21 @@
    Rebase On Dependent - https://wiki.openstack.org/wiki/Gerrit_Workflow#Rebase_On_Dependent
    Remote Rebasing
    ---------------

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

    Local rebasing.
    This requires copying the "cherry-pick" option provided in the child's patch set details of the Gerrit UI.
    The reason git review -R is done is because it should be up to the parent to rebase based on its parent. If a conflict occurs it should be their responsibility to fix the conflict and your responsibility to rebase off of that fix.
    Local rebasing
    --------------

    1. Checkout and create local branch of the dependent review - git review -d $PARENT_CHANGE_NUMBER
    2. Cherry-pick your review's most recent patch set - copied from Gerrit UI
    3. Push up - git review -R
    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



    Undo a git commit amend - http://stackoverflow.com/questions/1459150/how-to-undo-git-commit-amend-done-instead-of-git-commit
    Undo a git commit amend
    -----------------------

    git reflog (to find the number)
    git reset --soft HEAD@{number}
    git commit -C HEAD@{number}
    git commit -C HEAD@{number}
  20. @stevemart stevemart renamed this gist Sep 19, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions rebase on dependent → git tips and tricks
    Original file line number Diff line number Diff line change
    @@ -10,3 +10,11 @@ Local rebasing.
    1. Checkout and create local branch of the dependent review - git review -d $PARENT_CHANGE_NUMBER
    2. Cherry-pick your review's most recent patch set - copied from Gerrit UI
    3. Push up - git review -R



    Undo a git commit amend - http://stackoverflow.com/questions/1459150/how-to-undo-git-commit-amend-done-instead-of-git-commit

    git reflog (to find the number)
    git reset --soft HEAD@{number}
    git commit -C HEAD@{number}
  21. @stevemart stevemart created this gist Aug 27, 2014.
    12 changes: 12 additions & 0 deletions rebase on dependent
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    Rebase On Dependent - https://wiki.openstack.org/wiki/Gerrit_Workflow#Rebase_On_Dependent

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

    Local rebasing.
    This requires copying the "cherry-pick" option provided in the child's patch set details of the Gerrit UI.
    The reason git review -R is done is because it should be up to the parent to rebase based on its parent. If a conflict occurs it should be their responsibility to fix the conflict and your responsibility to rebase off of that fix.

    1. Checkout and create local branch of the dependent review - git review -d $PARENT_CHANGE_NUMBER
    2. Cherry-pick your review's most recent patch set - copied from Gerrit UI
    3. Push up - git review -R