3 ms·
In a script called `git-first-push`, on your path: #!/bin/zsh git push -u ${1:-origin} HEAD:"$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')"
by saidajigumi 8y ago
In a script called `git-first-push`, on your path:
#!/bin/zsh
git push -u ${1:-origin} HEAD:"$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')"
This means "push the current branch to origin (or the first argument, if specified) to a branch of the same name, when this hasn't been done before. Set origin (or the first arg) as the upstream of the local branch". Formally invoked as `git first-push [remote]`, I just alias it to `git fp`.
EDIT: I've forgotten offhand whether there are actual zsh-isms here. It's probably bash compatible, but I always have zsh installed by the time this script lands on a system.
- phamilton 8y agohow is this different from: git push -u origin head ?
- saidajigumi 8y agoGood point; I'd missed that someone taught git a smarter "spelling" for this task. IIRC, `git push -u origin HEAD` didn't used to automatically create a branch of the same name on that remote -- the explicit colon notion was required. I've had this little script around for a long time...
- majewsky 8y agoI just do git push -u which does what I want since I set git config --global push.default=current