简体   繁体   English

如何将 Git 的特定分支推送到我的服务器?

[英]How can I push a specific branch of Git to my server?

I'm working to deploy a Django app.我正在努力部署 Django 应用程序。 The app built on a Github OS project.该应用程序构建在 Github OS 项目上。 I have this stored locally as the Master branch.我将它存储在本地作为主分支。

$ git branch   
* master  
  customized - customized with local dev settings  
  webfaction_customized - with production server settings 

The customizations for this project are stored in 2 separate branches.此项目的自定义存储在 2 个独立的分支中。

My plan was to perform my customization locally in 'customized', then merge those changes into 'webfaction_customized'我的计划是在“customized”中本地执行我的自定义,然后将这些更改合并到“webfaction_customized”中

Then push these changes to a bare repository on the production_server: I would then clone this bare repository on the production_server, change the settings in the cloned repository and restart the fcgi process.然后将这些更改推送到 production_server 上的裸存储库:然后我将在 production_server 上克隆这个裸存储库,更改克隆存储库中的设置并重新启动 fcgi 进程。

The first problem was that I found this if I tried to push a branch to the server that wasn't master, I could not clone from the bare repository.第一个问题是,如果我尝试将一个分支推送到不是 master 的服务器,我发现了这一点,我无法从裸存储库克隆。

So I tried to push the master branch to the server.所以我尝试将 master 分支推送到服务器。

git push webfaction_server master

But now I'm finding that none of my branches are uploaded.但是现在我发现我的分支都没有上传。

Is there some way to push a specific branch to a bare repository and be able to clone that branch?有没有办法将特定分支推送到裸存储库并能够克隆该分支?

OR

Do I need to restructure my project so that Master branch is my customizations and the Github project would be in a github branch?我是否需要重构我的项目,以便 Master 分支是我的自定义,而 Github 项目将在 github 分支中?

You would simply do:你会简单地做:

git push origin webfaction_customized

Where origin is your remote name and webfaction_customized is your custom branch.其中 origin 是您的远程名称,而 webfaction_customized 是您的自定义分支。

Hence, when you work on the master branch, you are pushing via:因此,当您在 master 分支上工作时,您正在通过以下方式推送:

git push origin master

你会简单地做:

git push origin localBranchName:remoteBranchName

The message Warning: Remote HEAD refers to nonexistent ref, unable to checkout.消息Warning: Remote HEAD refers to nonexistent ref, unable to checkout. only tells you that the HEAD link does not exist and thus Git does not know which revision to check out to your local working directory.只告诉您 HEAD 链接不存在,因此 Git 不知道要检出哪个版本到您的本地工作目录。

Chances are that the branches on production_server themselves are created correctly.可能是production_server本身的分支是正确创建的。 Just do a git checkout <whatever-branch-you-want> and start hacking away.只需执行git checkout <whatever-branch-you-want>并开始破解。

If it doesn't solve the issue, paste here the output of git branch -a and cat .git/config run n both repos.如果它不能解决问题,请将git branch -acat .git/config run n 两个存储库的输出粘贴到此处。

Your push-command seems right, assuming webfaction_server is the name of a remote and not just the server address.您的推送命令似乎是正确的,假设webfaction_server远程的名称而不仅仅是服务器地址。 Run git help remote to learn more about pushing and pulling to/from multiple remotes.运行git help remote以了解有关向/从多个遥控器推送和拉动的更多信息。

you may need to update the server information with git-update-server-info .您可能需要使用git-update-server-info 更新服务器信息 This tool will update the HEAD information on the server with the recent commit hashes, updating old branches and making new branches visible.此工具将使用最近的提交哈希更新服务器上的 HEAD 信息,更新旧分支并使新分支可见。 In particular, it will update the info/refs file in your git repository.特别是,它将更新您的 git 存储库中的info/refs文件。 You will need to run this on the server, so, perhaps something like the following could be useful:您需要在服务器上运行它,因此,以下内容可能有用:

ssh webserver "cd /path/to/your/repository.git/ && git-update-server-info"

It might be possible to trigger that update, possibly with a post-commit hook, but have not tried that yet.可能会触发该更新,可能使用 post-commit 钩子,但还没有尝试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM