git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository.
To be able to push to your remote repository, you must ensure that all your changes to the local repository are committed.
This command’s syntax is as follows:
git push <repo name> <branch name>
There are a number of different options you can pass with the command, you can learn more about them in the Git documentation or run
git push --help.
Push to a Specific Remote Repository and Branch
In order to push code, you must first clone a repository to your local machine.
# Once a repo is cloned, you'll be working inside of the default branch (the default is `master`) git clone https://github.com/<git-user>/<repo-name> && cd <repo-name> # make changes and stage your files (repeat the `git add` command for each file, or use `git add .` to stage all) git add <filename> # now commit your code git commit -m "added some changes to my repo!" # push changes in `master` branch to github git push origin master
To learn more about branches check out the links below:
Push to a Specific Remote Repository and All Branches in it
If you want to push all your changes to the remote repository and all branches in it, you can use:
git push --all <REMOTE-NAME>
--allis the flag that signals that you want to push all branches to the remote repository
REMOTE-NAMEis the name of the remote repository you want to push to
Push to a specific branch with force parameter
If you want to ignore the local changes made to Git repository at Github(Which most of developers do for a hot fix to development server) then you can use —force command to push by ignoring those changs.
git push --force <REMOTE-NAME> <BRANCH-NAME>
REMOTE-NAMEis the name of the remote repository to which you want to push the changes to
BRANCH-NAMEis the name of the remote branch you want to push your changes to
Push ignoring Git’s pre-push hook
git push will trigger the
--verify toggle. This means that git will execute any client-side pre-push script that may have been configured. If the pre-push scripts fails, so will the git push. (Pre-Push hooks are good for doing things like, checking if commit messages confirm to company standards, run unit tests etc…). Occasionally you may wish to ignore this default behavior e.g. in the scenario where you wish to push your changes to a feature branch for another contributor to pull, but your work-in-progress changes are breaking unit tests. To ignore the hook, simply input your push command and add the flag
git push --no-verify