-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddremote
executable file
·39 lines (25 loc) · 1.05 KB
/
addremote
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
36
37
38
39
#!/bin/bash
set -ueo pipefail
read -r -d '' USAGE << EOM || true
$(basename $0) REMOTE PROJECT_FOLDER
* REMOTE IP or Hostname of the remote
Note: Change into the top level directory of your git project before running
Optional environmental variables:
* REMOTE_NAME Name that git uses for the remote. Defaults to REMOTE.
* USER Username on the remote server. Defaults to local username.
EOM
usage.sh "$USAGE" $@ && exit
REMOTE=${1:?Specify the hostname or IP of the remote}
PROJECT=${2:?Specify the project folder on the remote (without the git extension)}
REMOTE_NAME=${REMOTE_NAME:-$REMOTE}
USER=$USER
# Prevent pushing the wrong git project (must be in the top level directory)
if [ ! -d .git ]; then
echo "Please go to your top level git directory for the project you want to push"
exit
fi
git remote add $REMOTE_NAME $USER@$REMOTE:$PROJECT.git
echo "Added: $USER@$REMOTE:$PROJECT.git as the remote named $REMOTE_NAME"
echo 'Run the following command to upload all local branches to the remote'
echo "git push $REMOTE_NAME --all"
#git push $REMOTE_NAME --all