git push命令_Git Push命令解释

git push命令

The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository.

git push命令允许您将提交(或推送 )从本地Git存储库中的本地分支发送到远程存储库。

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.

您可以通过命令传递许多不同的选项,可以在Git文档中了解有关它们的更多信息,或运行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>

in which:

其中:

  • --all is the flag that signals that you want to push all branches to the remote repository

    --all是标志,表示您希望将所有分支推送到远程存储库

  • REMOTE-NAME is the name of the remote repository you want to push to

    REMOTE-NAME是您要推送到的远程存储库的名称

推入具有力参数的特定分支 (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.

如果您想忽略Github上对Git存储库所做的本地更改(大多数开发人员都在对开发服务器进行热修复),则可以使用–force命令来忽略这些更改。

git push --force <REMOTE-NAME> <BRANCH-NAME>

in which:

其中:

  • REMOTE-NAME is the name of the remote repository to which you want to push the changes to

    REMOTE-NAME是要将更改推送到的远程存储库的名称

  • BRANCH-NAME is the name of the remote branch you want to push your changes to

    BRANCH-NAME是您要将更改推送到的远程分支的名称

推忽略Git的预推钩 (Push ignoring Git’s pre-push hook)

By default 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 --no-verify

默认情况下, git push将触发--verify切换。 这意味着git将执行可能已配置的任何客户端预推脚本。 如果预推送脚本失败,则git push也将失败。 (Pre-Push挂钩非常适合执行诸如检查提交消息是否符合公司标准,运行单元测试等操作)。 有时,您可能希望忽略此默认行为,例如,在您希望将更改推送到功能分支以供其他贡献者提取但正在进行的更改破坏了单元测试的情况下。 要忽略该钩子,只需输入您的push命令并添加标志--no-verify

git push --no-verify

更多信息: (More Information:)

翻译自: https://www.freecodecamp.org/news/the-git-push-command-explained/

git push命令

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值