Git 工作流程 - 设置构建过程 [英] Git workflow - Setting up a build process
问题描述
免责声明:我已经使用 Git 一段时间了,但仍然觉得它令人困惑.
我正在为项目设置构建过程,但在更新 git 存储库时遇到问题.
- 我在服务器上创建了存储库,比如说 C:MyProject.
- 我使用 SourceTree 将我的计算机连接到存储库.拉一下并获取我的所有代码,到目前为止一切都很好.
- 我进行了提交,但收到一条错误消息:拒绝更新已检出的分支...默认情况下,拒绝更新非裸存储库中的当前分支"
- 稍微使用 Google,我意识到服务器上的 git 存储库不应该检出 master,因此我使用 Git GUI 检出并使用从本地分支分离"选项.这会将服务器上的分支设置为 HEAD.
现在是我感到困惑的部分(如果我之前真的感到困惑,只是不知道,请告诉我).更新服务器上的代码的推荐方法是什么?如果我在 Git GUI 中打开服务器存储库,则无法进行提取.如果我结帐大师似乎有效,但这实际上是推荐的吗?如果是这样,那就意味着我必须在每次更新后签出不同的分支,以便我可以继续在我的工作计算机上进行推送.
a>:参见git 中裸共享存储库的概念"和所有关于裸"存储库——什么,为什么,如何修复非裸推送.
这意味着在您的服务器上,您需要:
- 创建一个 Git 仓库(你已经做了)
- 克隆该存储库的裸存储库 (
git clone --bare yourProjectFolder yourProjectFolder.git
)
(.git
扩展名是裸仓库根文件夹的命名约定) 改为推送到那个裸仓库:
转到您的本地存储库,然后输入:git remote set-url origin/url/repo/repo/yourProjectFolder.git
在裸仓库中添加一个钩子(在服务器上,
yourProjectFolder.git/hooks/post-receive
),你在其中- 更改目录(到您的非裸仓库文件夹
yourProjectFolder
) 取消设置 GIT_DIR
git pull ../yourProjectFolder.git
- 更改目录(到您的非裸仓库文件夹
请参阅永久部署远程 nodejs 服务器".
Disclaimer: I've been using Git for a while but still find it confusing.
I'm setting a build process for a project and am running into a problem updating the git repository.
- I created the repository on the server, lets say C:MyProject.
- I connected my computer to the repository with SourceTree. Do a pull and get all my code, everything is great so far.
- I go to make a commit but get an error saying: "refusing to update checked out branch... By default, updating the current branch in a non-bare repository is denied"
- Use Google a bit, and I realize that the git repository on the server shouldn't have master checked out so I use Git GUI checkout using the option to "Detach from Local Branch". This sets the branch on the server to HEAD.
Now is the part where I'm confused (let me know if I was actually confused earlier and just don't know it). What is the recommended way to go about updating the code on the server? If I open the server repository in Git GUI there is no option to do a fetch. What seems to work is if I checkout master, but is that actually what's recommended? And if it is, then that would mean I have to checkout a different branch after each update so that I can continue doing pushes on my work computer.
It is a best practice to push to a bare repo: see "concept of bare shared repository in git" and all about "bare" repos -- what, why, and how to fix a non-bare push.
Which means on your server, you need to:
- create a Git repo (you already did)
- clone that repo a bare repo (
git clone --bare yourProjectFolder yourProjectFolder.git
)
(the.git
extention is a naming convention for bare repo root folder) push to that bare repo instead:
Go to your local repo, and type:git remote set-url origin /url/repo/repo/yourProjectFolder.git
add a hook in the bare repo (on the server,
yourProjectFolder.git/hooks/post-receive
), in which you- change directory (to your non-bare repo folder
yourProjectFolder
) unset GIT_DIR
git pull ../yourProjectFolder.git
- change directory (to your non-bare repo folder
See more at "Remote nodejs server deployment with forever".
这篇关于Git 工作流程 - 设置构建过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!