Created
May 11, 2022 21:39
-
-
Save carlzulauf/f491d19c4fc3a0e951f3f5a6dfa297c3 to your computer and use it in GitHub Desktop.
git pushu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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