git - 如何在 Git 中提交后自动推送?

标签 git githooks git-push post-commit-hook

如何设置Git自动推送到远程 每次提交到本地存储库后存储库(包括自动提供我的密码)?

最佳答案

首先,确保您可以在不提供密码的情况下手动推送。如果您通过 HTTP 或 HTTPS 进行推送,那么这将是 creating a .netrc file with the login details 的情况之一。或 adding your username and password into the URL for the remote .如果您使用的是 SSH,则可以创建私钥没有密码的 key 对,或者 use ssh-agent to cache your private key .

然后您应该在 .git/hooks/post-commit 中创建一个可执行 (chmod +x) 文件,其中包含以下内容:

#!/bin/sh
git push origin master

...如果您想推送到 origin 以外的远程,或者推送 master 以外的分支,请自定义该行。确保您使该文件可执行。

关于git - 如何在 Git 中提交后自动推送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7925850/

相关文章:

GIT预接收 Hook

git - 错误: RPC failed; HTTP 502 curl 22 The requested URL returned error: 502 Bad Gateway fatal

Linux 到 Windows 存储库 pull 和推送

Git merge 不获取新文件

Git 推送错误

github - 每次合并到 master 时触发 webhook - GitHub Webhooks

git - 如何在不同对应的本地分支package.json中使用单独的git分支作为npm包依赖?

php - 将 HTML 网站文件上传到 Openshift PHP 5.4

Git 找不到 .ssh

git push origin 被 fallthru 拒绝,hook 拒绝 : gitolite