如何在git中提交后自动推送? [英] How to automatically push after committing in git?

查看:679
本文介绍了如何在git中提交后自动推送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在每次提交本地回购后将git设置为自动推送到远程回购(包括自动提供密码短语)?

首先,请确保您可以在不提供密码的情况下手动推送。如果您推送HTTP或HTTPS,那将是创建包含登录信息的 .netrc 文件将您的用户名和密码添加到远程网址中。如果您使用的是SSH,则可以创建一个密钥对,其中私钥没有密码,或者使用 ssh-agent 来缓存您的私钥 然后你应该在 .git / hooks / post-commit 中创建一个包含以下内容的文件:

 #!/ bin / sh 
git push origin master

...如果要推送到 origin 以外的其他远程,或者推送除 master 以外的分支,则自定义该行。确保你使该文件成为可执行文件。


How do I set git to automatically push to a remote repo (including automatically providing my passphrase) after each commit to the local repo?

解决方案

First, make sure that you can push manually without providing your password. If you are pushing over HTTP or HTTPS, that will be a case of either creating a .netrc file with the login details or adding your username and password into the URL for the remote. If you're using SSH, you can either create a keypair where the private key doesn't have a password, or use ssh-agent to cache your private key.

Then you should create a file in .git/hooks/post-commit that contains the following:

#!/bin/sh
git push origin master

... customizing that line if you want to push to a remote other than origin, or push a branch other than master. Make sure that you make that file executable.

这篇关于如何在git中提交后自动推送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆