diff --git a/README.md b/README.md index cca8c3a..61980f6 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ get commit %MESSAGE% | git commit -m %MESSAGE% get branch %BRANCH% | stashes working tree, creates or switches branch, and checks out branch get rmbranch %BRANCH% | git branch -d %BRANCH% *TODO: rename?* get fetch | Fetches all remotes and fast-forwards local branches when possible +get fetch %BRANCHES% | Fetches and fast-forwards the specified branches get status | git status get review | git diff --cached get diff | compare working tree with HEAD (git diff HEAD) diff --git a/get b/get index 67bed06..adc9917 100644 --- a/get +++ b/get @@ -84,24 +84,23 @@ fetch) echo Updating if [ -z "$2" ]; then git fetch --all - # Fast-forward all local branches. I owe a lot to http://stackoverflow.com/a/24451300/2168416 - current_branch=$(git rev-parse --abbrev-ref HEAD) - for local_branch in $(list_branches); do - remote=$(git config --get branch.$local_branch.remote) - remote_branch=$(git config --get branch.$local_branch.merge | sed 's:refs/heads/::') - # Git throws an error if we try the fetch command on the current branch. Sheesh - if [ "$current_branch" = "$local_branch" ]; then - git merge --ff-only $remote/$remote_branch - else - git fetch $remote $remote_branch:$local_branch - fi - done + branches="$(list_branches)" else - git fetch "${@:2}" - for b in "${@:2}"; do - git fetch upstream "$b":"$b" - done + branches = "${@:2}" + git fetch "$branches" fi +# Fast-forward local branches. I owe a lot to http://stackoverflow.com/a/24451300/2168416 +current_branch=$(git rev-parse --abbrev-ref HEAD) +for local_branch in $branches; do + remote=$(git config --get branch.$local_branch.remote) + remote_branch=$(git config --get branch.$local_branch.merge | sed 's:refs/heads/::') + # Git throws an error if we try the fetch command on the current branch. Sheesh + if [ "$current_branch" = "$local_branch" ]; then + git merge --ff-only $remote/$remote_branch + else + git fetch $remote $remote_branch:$local_branch + fi +done ;; ignore)