This is a Bash script that automates common Git tasks, including initializing a repository, adding files, committing changes, creating branches, adding remotes, and pushing changes.
- Checks if Git is installed and prompts the user to install it if not.
- Configures Git username and email if not already set.
- Initializes a new Git repository if one doesn't exist.
- Allows the user to add all files or specify files to add.
- Commits changes with a user-provided commit message.
- Creates and switches to a new branch if specified.
- Adds a remote repository if a URL is provided if it is already exits then handles the error.
- Pushes changes to the specified remote and branch.
./git_automation.sh -m <commit-message> [-b <branch-name(default='main')>] [-r <remote-name(default='origin')>] [-u <remote-url>]-m : Commit message for the changes. (Required) -b : Name of the branch to push to. Default is main. -r : Name of the remote repository. Default is origin. -u : URL of the remote repository. If not provided, the script will not add a remote.
./git_automation.sh -m "Initial commit" -b "master" -r "origin" -u "https://github.com/username/repo.git"- Git must be installed on your system.
- The script must have executable permissions. You can set this with the command:
chmod +x git_automation.sh