-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_push
More file actions
executable file
·38 lines (31 loc) · 819 Bytes
/
Copy pathgit_push
File metadata and controls
executable file
·38 lines (31 loc) · 819 Bytes
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
#!/bin/bash
# Stage every tracked + new file, commit, and push to the current branch's remote.
# Usage:
# ./git_push -> prompts for a commit message
# ./git_push "commit message" -> uses the given message
set -e
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "$REPO_ROOT"
git add -A
if git diff --cached --quiet; then
echo "No changes to commit. Nothing to push."
exit 0
fi
echo ""
echo "===== Staged changes ====="
git status --short
echo "=========================="
echo ""
if [ -n "$1" ]; then
MSG="$*"
else
read -r -p "Commit message: " MSG
if [ -z "$MSG" ]; then
echo "Aborted: empty commit message."
git reset HEAD >/dev/null
exit 1
fi
fi
git commit -m "$MSG"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
git push -u origin "$BRANCH"