-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgit_add_me
executable file
·35 lines (26 loc) · 903 Bytes
/
git_add_me
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /bin/sh
# git_add_me (Bourne shell script) -- Adds a remote for my fork of the current project
# This will return 0 if on a branch or 1 if detached head (outputs nothing)
git_current_branch()
{
git branch | sed -n 's/^\* \(.*\)/\1/p' | grep -v '(no branch)'
}
# Outputs the name of the remote for the appropriate branch (current or
# specified, i.e. present in $branch) or nothing (and an non-zero exit code) if
# the branch doesn't exist or doesn't have a remote.
git_remote()
{
git config --get "branch.$(git_current_branch).remote"
}
# *** MAINLINE ***
set -e
r=$(git_remote)
url=$(git config --get "remote.$r.url" |
sed -e 's@.*/@@' -e 's/\.git$//' -e 's/.*/[email protected]:unixnut\/&.git/')
echo "Adding remote \"me\" pointing to $url"
git remote add me $url
: << EOT
[remote "me"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:unixnut/$reponame.git
EOT