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 .bashrcfrom your root directory. -
cdinto 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 originwithgit push -u originin source code. -
This pushes to the standard origin remote. If you would like to push to a different remote, simply change
git push origintogit push ${new_remote}.