Skip to content

Instantly share code, notes, and snippets.

@vitr
Forked from EvanDotPro/gittyup.sh
Created May 25, 2013 09:38

Revisions

  1. @EvanDotPro EvanDotPro revised this gist Jun 23, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -49,14 +49,14 @@ function gittyup()
    echo "Your working copy has uncommitted changes..."
    echo -e "These changes have been stashed and will be re-applied when we're done.\n"
    fi
    if [[ ! $currentBranch -eq 'master' ]]; then
    if [[ $currentBranch != 'master' ]]; then
    git checkout master
    fi
    git fetch --all
    git merge upstream/master --ff-only
    git push origin master

    if [[ ! $currentBranch -eq 'master' ]]; then
    if [[ $currentBranch != 'master' ]]; then
    git checkout $currentBranch
    fi
    if [[ ! $stashed -eq 0 ]]; then git stash pop --index; fi
  2. @EvanDotPro EvanDotPro revised this gist Jun 23, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -60,5 +60,4 @@ function gittyup()
    git checkout $currentBranch
    fi
    if [[ ! $stashed -eq 0 ]]; then git stash pop --index; fi
    }
    gittyup
    }
  3. @EvanDotPro EvanDotPro revised this gist Feb 9, 2012. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -40,19 +40,25 @@ function gittyup()
    {
    local gitCheck=$(git log -n1 2>&1 1>/dev/null | wc -l)
    if [[ ! $gitCheck -eq 0 ]]; then
    echo "Error: You're not in a Git repository"
    return
    echo "Error: You're not in a Git repository"
    return
    fi
    local currentBranch=$(git branch | grep \* | cut -d' ' -f2)
    local stashed=$(git stash | grep -v 'No local changes' | wc -l)
    if [[ ! $stashed -eq 0 ]]; then
    echo "Your working copy has uncommitted changes..."
    echo -e "These changes have been stashed and will be re-applied when we're done.\n"
    fi
    git checkout master
    if [[ ! $currentBranch -eq 'master' ]]; then
    git checkout master
    fi
    git fetch --all
    git merge upstream/master --ff-only
    git push origin master
    git checkout $currentBranch

    if [[ ! $currentBranch -eq 'master' ]]; then
    git checkout $currentBranch
    fi
    if [[ ! $stashed -eq 0 ]]; then git stash pop --index; fi
    }
    }
    gittyup
  4. @RWOverdijk RWOverdijk revised this gist Feb 9, 2012. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -40,19 +40,25 @@ function gittyup()
    {
    local gitCheck=$(git log -n1 2>&1 1>/dev/null | wc -l)
    if [[ ! $gitCheck -eq 0 ]]; then
    echo "Error: You're not in a Git repository"
    return
    echo "Error: You're not in a Git repository"
    return
    fi
    local currentBranch=$(git branch | grep \* | cut -d' ' -f2)
    local stashed=$(git stash | grep -v 'No local changes' | wc -l)
    if [[ ! $stashed -eq 0 ]]; then
    echo "Your working copy has uncommitted changes..."
    echo -e "These changes have been stashed and will be re-applied when we're done.\n"
    fi
    git checkout master
    if [[ ! $currentBranch -eq 'master' ]]; then
    git checkout master
    fi
    git fetch --all
    git merge upstream/master --ff-only
    git push origin master
    git checkout $currentBranch

    if [[ ! $currentBranch -eq 'master' ]]; then
    git checkout $currentBranch
    fi
    if [[ ! $stashed -eq 0 ]]; then git stash pop --index; fi
    }
    }
    gittyup
  5. @EvanDotPro EvanDotPro revised this gist Jan 3, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -39,13 +39,13 @@
    function gittyup()
    {
    local gitCheck=$(git log -n1 2>&1 1>/dev/null | wc -l)
    if [[ $gitCheck != 0 ]]; then
    if [[ ! $gitCheck -eq 0 ]]; then
    echo "Error: You're not in a Git repository"
    return
    fi
    local currentBranch=$(git branch | grep \* | cut -d' ' -f2)
    local stashed=$(git stash | grep -v 'No local changes' | wc -l)
    if [[ $stashed != 0 ]]; then
    if [[ ! $stashed -eq 0 ]]; then
    echo "Your working copy has uncommitted changes..."
    echo -e "These changes have been stashed and will be re-applied when we're done.\n"
    fi
    @@ -54,5 +54,5 @@ function gittyup()
    git merge upstream/master --ff-only
    git push origin master
    git checkout $currentBranch
    if [[ $stashed != 0 ]]; then git stash pop --index; fi
    if [[ ! $stashed -eq 0 ]]; then git stash pop --index; fi
    }
  6. @EvanDotPro EvanDotPro revised this gist Dec 21, 2011. 1 changed file with 41 additions and 45 deletions.
    86 changes: 41 additions & 45 deletions gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -1,62 +1,58 @@
    ###############################################################
    ## ##
    ## gittyup() - Easily keep master in sync with upstream. ##
    ## ##
    ## Author: Evan Coury, http://blog.evan.pro/ ##
    ## URL: https://gist.github.com/1506822 ##
    ## ##
    ## This bash function is a simple shortcut for keeping your ##
    ## local (and public fork / origin remote) master branch up ##
    ## to date and in sync with the upstream master. ##
    ## ##
    ## To use gittyup(), simply drop this in your ~/.bashrc. ##
    ## ##
    ## A few assumptions are made: ##
    ## ##
    ## - The remote you are updating from is named upstream. ##
    ## - You have a remote named origin that you can push to. ##
    ## - Your local master branch has not diverged from the ##
    ## upstream master (always work in topic branches) ##
    ## ##
    ## gittyup() performs all of the following tasks for you: ##
    ## ##
    ## 0. Verify that you are in a valid Git repo. ##
    ## 1. Remember which branch you are on. ##
    ## 2. Stash any uncommitted changes you have. ##
    ## 3. Checkout master. ##
    ## 4. Fetch all remotes. (nice to track other remotes) ##
    ## 5. Merge upstream/master into local master (FF ONLY!) ##
    ## 6. Push your updated local master branch to origin. ##
    ## 7. Check out the branch you were previously on. ##
    ## 8. Applies any stashed changes and index status. ##
    ## ##
    ## It _should_ be safe to run gittyup() in any repo where ##
    ## the assumptions above hold true. You can run gittyup() ##
    ## even when your repository is in a dirty state ##
    ## (uncommitted / unstaged changes) and regardless of which ##
    ## branch you are working in. After gittyup() is finished, ##
    ## it will return you to the branch you were working in and ##
    ## restore your working tree and index to the exact state ##
    ## it was in before running gittyup(). ##
    ## ##
    ###############################################################
    ####################################################################################
    ## ##
    ## gittyup() - Easily keep master in sync with upstream. ##
    ## ##
    ## Author: Evan Coury, http://blog.evan.pro/ ##
    ## URL: https://gist.github.com/1506822 ##
    ## ##
    ## This bash function is a simple shortcut for keeping your local (and public ##
    ## fork / origin remote) master branch up to date and in sync with the upstream ##
    ## master. To use gittyup(), simply drop this in your ~/.bashrc. ##
    ## ##
    ## A few assumptions are made: ##
    ## ##
    ## - The remote you are updating from is named upstream. ##
    ## - You have a remote named origin that you can push to. ##
    ## - You always work in topic branches and your local master branch has not ##
    ## diverged from the upstream master. ##
    ## ##
    ## gittyup() performs all of the following tasks for you: ##
    ## ##
    ## 0. Verify that you are in a valid Git repo. ##
    ## 1. Remember which branch you are on. ##
    ## 2. Stash any uncommitted changes you have. ##
    ## 3. Checkout master. ##
    ## 4. Fetch all remotes. (nice to track other remotes) ##
    ## 5. Merge upstream/master into local master (FF ONLY!) ##
    ## 6. Push your updated local master branch to origin. ##
    ## 7. Check out the branch you were previously on. ##
    ## 8. Applies any stashed changes and index status. ##
    ## ##
    ## It _should_ be safe to run gittyup() in any repo where the assumptions above ##
    ## hold true. You can run gittyup() even when your repository is in a dirty ##
    ## state (uncommitted / unstaged changes) and regardless of which branch you ##
    ## are working in. After gittyup() is finished, it will return you to the ##
    ## branch you were working in and restore your working tree and index to the ##
    ## exact state it was in before running gittyup(). ##
    ## ##
    ####################################################################################
    function gittyup()
    {
    local gitCheck=$(git log -n1 2>&1 1>/dev/null | wc -l)
    if [[ $gitCheck != 0 ]]; then
    echo "Error: You're not in a Git repository"
    echo "Error: You're not in a Git repository"
    return
    fi
    local currentBranch=$(git branch | grep \* | cut -d' ' -f2)
    local stashed=$(git stash | grep -v 'No local changes' | wc -l)
    if [[ $stashed != 0 ]]; then
    echo "Your working copy has uncommitted changes..."
    echo -e "These changes have been stashed and will be re-applied when we're done.\n"
    fi
    fi
    git checkout master
    git fetch --all
    git merge upstream/master --ff-only
    git push origin master
    git checkout $currentBranch
    if [[ $stashed != 0 ]]; then git stash pop --index; fi
    if [[ $stashed != 0 ]]; then git stash pop --index; fi
    }
  7. @EvanDotPro EvanDotPro revised this gist Dec 21, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    ## gittyup() - Easily keep master in sync with upstream. ##
    ## ##
    ## Author: Evan Coury, http://blog.evan.pro/ ##
    ## URL: https://gist.github.com/{TBD} ##
    ## URL: https://gist.github.com/1506822 ##
    ## ##
    ## This bash function is a simple shortcut for keeping your ##
    ## local (and public fork / origin remote) master branch up ##
  8. @EvanDotPro EvanDotPro created this gist Dec 21, 2011.
    62 changes: 62 additions & 0 deletions gittyup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    ###############################################################
    ## ##
    ## gittyup() - Easily keep master in sync with upstream. ##
    ## ##
    ## Author: Evan Coury, http://blog.evan.pro/ ##
    ## URL: https://gist.github.com/{TBD} ##
    ## ##
    ## This bash function is a simple shortcut for keeping your ##
    ## local (and public fork / origin remote) master branch up ##
    ## to date and in sync with the upstream master. ##
    ## ##
    ## To use gittyup(), simply drop this in your ~/.bashrc. ##
    ## ##
    ## A few assumptions are made: ##
    ## ##
    ## - The remote you are updating from is named upstream. ##
    ## - You have a remote named origin that you can push to. ##
    ## - Your local master branch has not diverged from the ##
    ## upstream master (always work in topic branches) ##
    ## ##
    ## gittyup() performs all of the following tasks for you: ##
    ## ##
    ## 0. Verify that you are in a valid Git repo. ##
    ## 1. Remember which branch you are on. ##
    ## 2. Stash any uncommitted changes you have. ##
    ## 3. Checkout master. ##
    ## 4. Fetch all remotes. (nice to track other remotes) ##
    ## 5. Merge upstream/master into local master (FF ONLY!) ##
    ## 6. Push your updated local master branch to origin. ##
    ## 7. Check out the branch you were previously on. ##
    ## 8. Applies any stashed changes and index status. ##
    ## ##
    ## It _should_ be safe to run gittyup() in any repo where ##
    ## the assumptions above hold true. You can run gittyup() ##
    ## even when your repository is in a dirty state ##
    ## (uncommitted / unstaged changes) and regardless of which ##
    ## branch you are working in. After gittyup() is finished, ##
    ## it will return you to the branch you were working in and ##
    ## restore your working tree and index to the exact state ##
    ## it was in before running gittyup(). ##
    ## ##
    ###############################################################
    function gittyup()
    {
    local gitCheck=$(git log -n1 2>&1 1>/dev/null | wc -l)
    if [[ $gitCheck != 0 ]]; then
    echo "Error: You're not in a Git repository"
    return
    fi
    local currentBranch=$(git branch | grep \* | cut -d' ' -f2)
    local stashed=$(git stash | grep -v 'No local changes' | wc -l)
    if [[ $stashed != 0 ]]; then
    echo "Your working copy has uncommitted changes..."
    echo -e "These changes have been stashed and will be re-applied when we're done.\n"
    fi
    git checkout master
    git fetch --all
    git merge upstream/master --ff-only
    git push origin master
    git checkout $currentBranch
    if [[ $stashed != 0 ]]; then git stash pop --index; fi
    }