forked from siv-the-programmer/auto_github_repo_add
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_add.sh
More file actions
50 lines (39 loc) · 1.29 KB
/
git_add.sh
File metadata and controls
50 lines (39 loc) · 1.29 KB
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
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Git auto uploader with file picker
#-----------------------------------------
# Created this file so that i dont manually have to git add add git commit git pull and git push
# List all files in current directory (excluding .git)
echo "Files in current directory:"
mapfile -t files < <(find . -maxdepth 1 -type f ! -name ".git*" -printf "%f\n")
# If no files found
if [[ ${#files[@]} -eq 0 ]]; then
echo "No files found in this directory."
exit 1
fi
# Display files with numbers
for i in "${!files[@]}"; do
echo "$((i+1)). ${files[$i]}"
done
# Ask user to pick a file
read -p "Select the file number you want to upload: " choice
# Validate input
if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 || choice > ${#files[@]} )); then
echo "Invalid choice."
exit 1
fi
filename="${files[$((choice-1))]}"
# Ask for commit message
read -p "Enter commit message: " commit_msg
# Detect current branch automatically
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ -z "$branch" ]]; then
echo "Not a git repository or unable to detect branch."
exit 1
fi
# Pull latest changes
echo "Pulling latest changes from remote..."
git pull origin "$branch"
git add "$filename"
git commit -m "$commit_msg"
git push origin "$branch"
echo "'$filename' successfully committed and pushed to '$branch'!"