/
bash_code
/
gitjet
Обзор
Документация
Войти
/
bash_code
/
gitjet
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
gitjet_en
83 строки
2 KB
codesshaman
initial commit
08 апр 2026, 15:00
08 апр 2026, 15:00
c1e5c52
Код
Авторство
О чём код?
#!/bin/bash # ============================== # Settings # ============================== FIRST_COMMIT_MSG="initial commit" BRANCH_NAME="master" GIT_NAME="git_username" GIT_MAIL="git_user_email" # ============================== # Checking arguments # ============================== if [ $# -eq 0 ]; then echo "Error: Specify the address of the remote repository as an argument. " echo "Example: $0 https://github.com/user/repo.git" exit 1 fi REMOTE_URL="$1" # ============================== # Defining the path and directory # ============================== read -p "Enter the path to the local directory to initialize the repository (current by default): " LOCAL_PATH if [ -z "$LOCAL_PATH" ]; then LOCAL_PATH="$(pwd)" fi # Creating a directory if there is none if [ ! -d "$LOCAL_PATH" ]; then mkdir -p "$LOCAL_PATH" fi # ============================== # Extract the directory name as a # suggestion for the project name # ============================== DEFAULT_PROJECT_NAME="$(basename "$LOCAL_PATH")" # ============================== # Project Name confirmation # ============================== read -p "Использовать '$DEFAULT_PROJECT_NAME' как имя проекта? [Y/n]: " CONFIRM if [[ "$CONFIRM" =~ ^[Nn]$ ]]; then read -p "Введите имя проекта вручную: " PROJECT_NAME else PROJECT_NAME="$DEFAULT_PROJECT_NAME" fi # ============================== # Основная логика Git # ============================== cd "$LOCAL_PATH" || exit 1 git init # Creating README.md echo "# $PROJECT_NAME" >> README.md git add . # Setting up a Git user git config user.name "$GIT_NAME" git config user.email "$GIT_MAIL" # Checking the configuration git config --local --list # The first commit git commit -m "$FIRST_COMMIT_MSG" # Renaming the branch git branch -M "$BRANCH_NAME" # Adding a remote repository git remote add origin "$REMOTE_URL" # Push to the main branch git push -u origin "$BRANCH_NAME" echo "✅ The repository has been successfully initialized to '$LOCAL_PATH' with the project name '$PROJECT_NAME'."