This script will:
- stage all your changes, i.e.
git add .
- commit your changes with a message, i.e.
git commit -m ${command_line_argument}
- push changes to your repository, i.e.
git push origin ${current_git_branch}
This script will also throw an error if you try to push directly to master. You must instead push to a different branch and merge that with master directly on GitHub, GitLab, etc.
-
Make sure you're using a bash shell.
-
Download the .bashrc file from this repo and add it to your root directory. If you already have a .bashrc file, simply copy and paste the code.
-
Open a terminal and run
source .bashrc
from your root directory. -
cd
into the directory with the git code you want to update. -
Run
git-no-master ${commit_message}
in the command line. Examples,git-no-master "initial commit"
.
All set! The script gets your current branch and automatically pushes to that branch on the origin remote, unless you're on the master branch.
-
This requires setting up the tracking reference initially, i.e.
git push -u origin ${branch_name}
. This is intended to prevent creating new branches on the repo by accident. To allow this, simply replacegit push origin
withgit push -u origin
in source code. -
This pushes to the standard origin remote. If you would like to push to a different remote, simply change
git push origin
togit push ${new_remote}
.