Skip to content

Instantly share code, notes, and snippets.

@dixudx
Forked from fernandoaleman/INSTALL.txt
Created November 28, 2018 03:08
Show Gist options
  • Save dixudx/e56435e89361e4bc50db802687fb03e0 to your computer and use it in GitHub Desktop.
Save dixudx/e56435e89361e4bc50db802687fb03e0 to your computer and use it in GitHub Desktop.

Revisions

  1. @fernandoaleman fernandoaleman revised this gist Sep 8, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion INSTALL.txt
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,4 @@

    Example:

    git-sync-fork origin fernandoaleman
    git-sync-fork upstream origin
  2. @fernandoaleman fernandoaleman revised this gist Sep 8, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git-sync-fork
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@ usage() {
    echo "Usage:"
    echo "$0 <upstream-remote> <target-remote>"
    echo ""
    echo "Example which ensures remote named 'fernandoaleman' have all the same branches and tags as 'origin'"
    echo "$0 origin fernandoaleman"
    echo "Example which ensures remote named 'origin' have all the same branches and tags as 'upstream'"
    echo "$0 upstream origin"
    exit 1
    }

  3. @fernandoaleman fernandoaleman revised this gist Sep 8, 2016. 1 changed file with 15 additions and 13 deletions.
    28 changes: 15 additions & 13 deletions git-sync-fork
    Original file line number Diff line number Diff line change
    @@ -4,37 +4,39 @@ UPSTREAM=$1
    MYREPO=$2

    usage() {
    echo "Usage:"
    echo "$0 <upstream-remote> <target-remote>"
    echo ""
    echo "Example which ensures remote named 'fernandoaleman' have all the same branches and tags as 'origin'"
    echo "$0 origin fernandoaleman"
    exit 1
    echo "Usage:"
    echo "$0 <upstream-remote> <target-remote>"
    echo ""
    echo "Example which ensures remote named 'fernandoaleman' have all the same branches and tags as 'origin'"
    echo "$0 origin fernandoaleman"
    exit 1
    }

    if [ -z "$UPSTREAM" ]
    then
    echo Missing upstream remote name.
    usage
    echo "Missing upstream remote name."
    usage
    fi

    if [ -z "$MYREPO" ]
    then
    echo Missing target remote name.
    usage
    echo "Missing target remote name."
    usage
    fi

    read -p "1. This will setup '$MYREPO' to track all branches in '$UPSTREAM' - Are you sure ?" -n 1 -r

    if [[ $REPLY =~ ^[Yy]$ ]]
    then
    for brname in `git branch -r | grep "$UPSTREAM" | grep -v master | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname $UPSTREAM/$brname ; done
    echo "\n"
    for brname in `git branch -r | grep "$UPSTREAM" | grep -v master | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname $UPSTREAM/$brname ; done
    fi

    read -p "2. This will push all local branches and tags into '$MYREPO' - Are you sure ?" -n 1 -r

    if [[ $REPLY =~ ^[Yy]$ ]]
    then
    git push --all $MYREPO
    git push --tags $MYREPO
    echo "\n"
    git push --all $MYREPO
    git push --tags $MYREPO
    fi
  4. @fernandoaleman fernandoaleman revised this gist Sep 8, 2016. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions INSTALL.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    1. Copy 'git-sync-fork' script code from gist
    2. Create a file called 'git-sync-fork' in any 'bin' directory in your $PATH
    3. Paste script into this new file 'git-sync-fork' and save
    4. Make the file executable `chmod +x git-sync-fork`
    5. Run the script inside your locally forked git repo

    Example:

    git-sync-fork origin fernandoaleman
  5. @fernandoaleman fernandoaleman created this gist Sep 8, 2016.
    40 changes: 40 additions & 0 deletions git-sync-fork
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/bin/sh

    UPSTREAM=$1
    MYREPO=$2

    usage() {
    echo "Usage:"
    echo "$0 <upstream-remote> <target-remote>"
    echo ""
    echo "Example which ensures remote named 'fernandoaleman' have all the same branches and tags as 'origin'"
    echo "$0 origin fernandoaleman"
    exit 1
    }

    if [ -z "$UPSTREAM" ]
    then
    echo Missing upstream remote name.
    usage
    fi

    if [ -z "$MYREPO" ]
    then
    echo Missing target remote name.
    usage
    fi

    read -p "1. This will setup '$MYREPO' to track all branches in '$UPSTREAM' - Are you sure ?" -n 1 -r

    if [[ $REPLY =~ ^[Yy]$ ]]
    then
    for brname in `git branch -r | grep "$UPSTREAM" | grep -v master | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname $UPSTREAM/$brname ; done
    fi

    read -p "2. This will push all local branches and tags into '$MYREPO' - Are you sure ?" -n 1 -r

    if [[ $REPLY =~ ^[Yy]$ ]]
    then
    git push --all $MYREPO
    git push --tags $MYREPO
    fi