Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Created May 11, 2022 21:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save carlzulauf/f491d19c4fc3a0e951f3f5a6dfa297c3 to your computer and use it in GitHub Desktop.
git pushu
#!/usr/bin/env ruby
# git pushu
# ---------
#
# Push upstream every time
#
# * If the current branch tracks a remote, push to it.
#
# * If there is no tracking branch, point to a branch of the same name,
# on the first remote listed in `git remote`
#
# TODO: make remote configurable
local_branch = `git name-rev --name-only HEAD`.strip
remote_repo = `git remote`.lines.first.strip
remote_branch = `git config branch.#{local_branch}.merge`
def run(command)
puts command
exec command
end
if remote_branch.empty?
run "git push --set-upstream #{remote_repo} #{local_branch}"
else
run "git push"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment