Skip to content

Instantly share code, notes, and snippets.

@mtking2
Last active August 30, 2019 21:15
Show Gist options
  • Select an option

  • Save mtking2/3a150134794edc57dda797850823a69a to your computer and use it in GitHub Desktop.

Select an option

Save mtking2/3a150134794edc57dda797850823a69a to your computer and use it in GitHub Desktop.

Revisions

  1. mtking2 revised this gist Aug 30, 2019. No changes.
  2. mtking2 revised this gist Apr 4, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -72,10 +72,10 @@ if [[ $remotes =~ upstream ]]; then
    if [ $working_branch == master ]; then
    plum_and_pom
    else
    echo -e "${blue}Checking out master branch${white}"
    echo -e "${blue}Checking out ${yellow}master${blue} branch${white}"
    git checkout master
    plum_and_pom
    echo -e "${blue}Checking back into $working_branch branch${white}"
    echo -e "${blue}Checking back into ${yellow}$working_branch${blue} branch${white}"
    git checkout $working_branch
    plom_and_powb $working_branch
    fi
  3. mtking2 revised this gist Aug 30, 2018. No changes.
  4. mtking2 revised this gist Aug 30, 2018. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -33,10 +33,6 @@ Just throw this in a file somewhere, `chmod 755` that bad boy, and then `export
    * when on `master` branch
    1. `git push origin master` (*nothing really to do here but go ahead and pull origin master because why not*)

    ## TODO's

    - [ ] automagically stash uncommitted changes (if any) beforehand and then pop stash once sync is done

    ##

    ```bash
    @@ -95,3 +91,7 @@ fi

    echo -e "done ${green}${white}"
    ```

    ## TODO's

    - [ ] automagically stash uncommitted changes (if any) beforehand and then pop stash once sync is done
  5. mtking2 revised this gist Aug 30, 2018. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ Just throw this in a file somewhere, `chmod 755` that bad boy, and then `export

    ## Breakdown of commands for various cases

    #### With upstream remote
    ### With upstream remote

    * when on `some-working-branch`
    1. `git checkout master`
    @@ -23,7 +23,7 @@ Just throw this in a file somewhere, `chmod 755` that bad boy, and then `export
    1. `git pull upstream master`
    2. `git push origin master`

    #### Without upstream remote
    ### Without upstream remote

    * when on `some-working-branch`
    1. `git pull origin master`
    @@ -37,6 +37,8 @@ Just throw this in a file somewhere, `chmod 755` that bad boy, and then `export

    - [ ] automagically stash uncommitted changes (if any) beforehand and then pop stash once sync is done

    ##

    ```bash
    #!/bin/bash
    blue="\033[0;34m"
  6. mtking2 revised this gist Aug 30, 2018. 1 changed file with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,37 @@ If you don't have an upstream remote then it will just pull and push to origin a

    Just throw this in a file somewhere, `chmod 755` that bad boy, and then `export PATH="path/to/script:$PATH"` in your favorite `~/.rc` file to run from anywhere.

    ## Breakdown of commands for various cases

    #### With upstream remote

    * when on `some-working-branch`
    1. `git checkout master`
    2. `git pull upstream master`
    3. `git push origin master`
    4. `git checkout some-working-branch` (*it will remember your working branch and automatically check back into it*)
    5. `git pull origin master`
    6. `git push origin some-working-branch`


    * when on `master` branch
    1. `git pull upstream master`
    2. `git push origin master`

    #### Without upstream remote

    * when on `some-working-branch`
    1. `git pull origin master`
    2. `git push origin some-working-branch`


    * when on `master` branch
    1. `git push origin master` (*nothing really to do here but go ahead and pull origin master because why not*)

    ## TODO's

    - [ ] automagically stash uncommitted changes (if any) beforehand and then pop stash once sync is done

    ```bash
    #!/bin/bash
    blue="\033[0;34m"
  7. mtking2 revised this gist Aug 30, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitsync.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Git Upstream/Origin Sync

    This script will sync your origin with upstream master, whether you're on master or checked-out on a working branch
    This script will sync your origin with upstream master, whether you're currently on master or checked-out on a working branch.

    If you don't have an upstream remote then it will just pull and push to origin accordingly.

  8. mtking2 revised this gist Aug 30, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@ This script will sync your origin with upstream master, whether you're on master

    If you don't have an upstream remote then it will just pull and push to origin accordingly.

    Just throw this in a file somewhere, `chmod 755` that bad boy, and then `export PATH="path/to/script:$PATH"` in your favorite `~/.rc` file to run from anywhere.

    ```bash
    #!/bin/bash
    blue="\033[0;34m"
  9. mtking2 revised this gist Aug 30, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@

    This script will sync your origin with upstream master, whether you're on master or checked-out on a working branch

    If you don't have an upstream remote then it will just pull and push to origin accordingly.

    ```bash
    #!/bin/bash
    blue="\033[0;34m"
  10. mtking2 revised this gist Aug 30, 2018. 1 changed file with 34 additions and 16 deletions.
    50 changes: 34 additions & 16 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    # Git Upstream Sync
    # Git Upstream/Origin Sync

    This script will sync your origin with upstream master, whether you're on master or checked-out on a working branch

    ```bash
    #!/bin/bash
    blue="\033[0;34m"
    green="\033[0;32m"
    yellow='\033[0;33m'
    white="\033[0m"

    # get currently checked-out branch
    @@ -14,28 +15,45 @@ parse_git_branch() {
    echo -e $branch
    }

    # pull upstream and push origin
    plom_and_pom() {
    echo -e "${blue}Pulling in upstream master$white"
    # pull upstream master and push origin master
    plum_and_pom() {
    echo -e "${blue}Pulling in upstream ${yellow}master$white"
    git pull upstream master
    echo -e "${blue}Pushing updates to origin$white"
    echo -e "${blue}Pushing updates to origin ${yellow}master$white"
    git push origin master
    }

    # pull origin master and push origin working branch
    plom_and_powb() {
    echo -e "${blue}Pulling origin ${yellow}master$blue into $yellow$1$white"
    git pull origin master
    echo -e "${blue}Pushing updates to origin $yellow$1$white"
    git push origin $1
    }

    working_branch=$(parse_git_branch)
    remotes="$(git remote show)"

    if [ $working_branch == master ]; then
    plom_and_pom
    if [[ $remotes =~ upstream ]]; then
    # does have upstream remote
    if [ $working_branch == master ]; then
    plum_and_pom
    else
    echo -e "${blue}Checking out master branch${white}"
    git checkout master
    plum_and_pom
    echo -e "${blue}Checking back into $working_branch branch${white}"
    git checkout $working_branch
    plom_and_powb $working_branch
    fi
    else
    echo -e "${blue}Checking out master branch${white}"
    git checkout master
    plom_and_pom
    echo -e "${blue}Checking back into $working_branch branch${white}"
    git checkout $working_branch
    echo -e "${blue}Pulling local master into $working_branch${white}"
    git pull origin master
    echo -e "${blue}Pushing updates to origin $working_branch${white}"
    git push origin $working_branch
    # does not have upstream remote
    if [ $working_branch == master ]; then
    echo -e "${blue}Pulling origin ${yellow}master$blue for kick and giggles${white}"
    git pull origin master
    else
    plom_and_powb $working_branch
    fi
    fi

    echo -e "done ${green}${white}"
  11. Michael revised this gist Aug 24, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gitsync.md
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,7 @@ else
    git pull origin master
    echo -e "${blue}Pushing updates to origin $working_branch${white}"
    git push origin $working_branch
    echo -e "done ${green}${white}"
    fi

    echo -e "done ${green}${white}"
    ```
  12. Michael revised this gist Aug 24, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitsync.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Git Upstream Sync

    This script will sync your origin with upstream master, whether you're.
    This script will sync your origin with upstream master, whether you're on master or checked-out on a working branch

    ```bash
    #!/bin/bash
  13. Michael created this gist Aug 24, 2018.
    41 changes: 41 additions & 0 deletions gitsync.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    # Git Upstream Sync

    This script will sync your origin with upstream master, whether you're.

    ```bash
    #!/bin/bash
    blue="\033[0;34m"
    green="\033[0;32m"
    white="\033[0m"

    # get currently checked-out branch
    parse_git_branch() {
    local branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
    echo -e $branch
    }

    # pull upstream and push origin
    plom_and_pom() {
    echo -e "${blue}Pulling in upstream master$white"
    git pull upstream master
    echo -e "${blue}Pushing updates to origin$white"
    git push origin master
    }

    working_branch=$(parse_git_branch)

    if [ $working_branch == master ]; then
    plom_and_pom
    else
    echo -e "${blue}Checking out master branch${white}"
    git checkout master
    plom_and_pom
    echo -e "${blue}Checking back into $working_branch branch${white}"
    git checkout $working_branch
    echo -e "${blue}Pulling local master into $working_branch${white}"
    git pull origin master
    echo -e "${blue}Pushing updates to origin $working_branch${white}"
    git push origin $working_branch
    echo -e "done ${green}${white}"
    fi
    ```