Git推送错误';[远程拒绝]主机->;master(分支机构当前已签出)和#x27;
昨天,我发布了一个关于如何将存储库从一台机器克隆到另一台机器的问题 我现在能够成功地将Git存储库从源代码(192.168.1.2)克隆到目标代码(192.168.1.1) 但是当我对一个文件进行编辑时,Git推送错误';[远程拒绝]主机->;master(分支机构当前已签出)和#x27;,git,git-push,Git,Git Push,昨天,我发布了一个关于如何将存储库从一台机器克隆到另一台机器的问题 我现在能够成功地将Git存储库从源代码(192.168.1.2)克隆到目标代码(192.168.1.1) 但是当我对一个文件进行编辑时,git commit-a-m“test”和git push,我在我的目的地(192.168.1.1)上得到了这个错误: 我正在使用两个不同版本的Git(1.7在远程计算机上,1.5在本地计算机上)。这是一个可能的原因吗?您应该只推到一个空存储库。裸存储库是没有签出分支的存储库。如果要将cd刻录到
git commit-a-m“test”
和git push
,我在我的目的地(192.168.1.1)上得到了这个错误:
我正在使用两个不同版本的Git(1.7在远程计算机上,1.5在本地计算机上)。这是一个可能的原因吗?您应该只推到一个空存储库。裸存储库是没有签出分支的存储库。如果要将cd刻录到裸存储库目录,则只能看到.git目录的内容。错误消息描述了发生的情况。更现代的Git版本拒绝在分支签出时通过推送更新该分支 在两个非裸存储库之间工作的最简单方法是
头
更改为与远程存储库上的索引和工作树不一致。
这将使意外提交一个更改变得非常容易,该更改将撤消所有推送的更改,同时也使您很难区分任何未提交的本地更改和新
头之间的差异,在我开始学习的时候,由于推送移动头部而导致的索引和工作树出现了相同的错误。其他一些答案显然不适合Git新手
(我将使用非技术术语来表达我的想法。)不管怎样,现在的情况是,您有两个存储库,一个是您第一次制作的原始版本,另一个是您刚刚制作的作品
现在,您在工作存储库中,正在使用“主”分支。但您也碰巧在原始存储库中“登录”到同一个“主”分支。既然你已经“登录”了原版,Git担心你可能会搞砸,因为你可能在原版上工作,把事情搞砸了。因此,您需要返回到原始存储库并执行“git checkout someotherbranch”,现在您可以毫无问题地进行推送
我希望这会有所帮助。您可以简单地将远程存储库转换为裸存储库(裸存储库中没有工作副本-该文件夹仅包含实际的存储库数据)
在远程存储库文件夹中执行以下命令:
git config --bool core.bare true
然后删除该文件夹中除.git
以外的所有文件。然后,您将能够对远程存储库执行git push
,而不会出现任何错误。事实上,将远程存储库设置为未签出的分支就足够了。在其他分支签出遥控器后,您可以推送。您可以通过编辑目标服务器上的.git/config
绕过此“限制”。添加以下内容以允许将git存储库推送到,即使它已“签出”:
或
第一个将允许推送,同时警告可能会弄乱分支,而第二个将只是安静地允许推送
这可用于将代码“部署”到不用于编辑的服务器。这不是最好的方法,而是部署代码的快速方法。我也有同样的问题。对我来说,我使用Git push将代码移动到我的服务器。我从不更改服务器端的代码,所以这是安全的
在存储库中,您正在推动键入:
git config receive.denyCurrentBranch ignore
这将允许您在存储库作为工作副本时对其进行更改
运行Git推送后,转到远程计算机并键入以下内容:
git checkout -f
这将使您所做的更改反映在远程计算机的工作副本中
请注意,如果您对要推送到的工作副本进行更改,这并不总是安全的。您可以重新创建服务器存储库,并从本地分支主机推送到服务器主机
在远程服务器上:
好的,您当地的分支机构:
我喜欢在remote box上仍然有一个可用的存储库的想法,但我喜欢使用以下替代虚拟分支:
git checkout --detach
这似乎是的一个非常新的特性-我正在使用git版本1.7.7.4。我发现可能对其他人有用的一篇文章是
我有一个在Git版本控制下的项目,我想把它升级到DC中的(VDE)。VDE运行5次
我读到的关于Git的文章中没有一篇提到裸存储库。这一切听起来都很简单,直到我尝试了我认为应该很容易从一个背景
这里的建议是让远程存储库正常工作。更符合我的要求的是将Xcode项目克隆到projectname.git
,并将其复制到远程服务器;然后他神奇地工作了。下一步是让Xcode在提交时不出错地推送,但现在我可以从终端执行
因此:
cd/tmp(或系统上的其他目录)
git clone--裸/xcode项目目录projectname.git
scp-r projectname.gitsshusername@remotehost.com:repos/
在Xcode中提交更改后,从Xcode项目推送更改:
cd /xcode-project-directory<br/>
git push sshusername@remotehost.com:repos/projectname.git<br/>
cd/xcode项目目录
git推送sshusername@remotehost.com:repos/projectname.git
我确信有一种更为流畅、更为复杂的方法来完成上述任务,b
git checkout -f
mkdir myrepo.git
cd myrepo.git
git init --bare
git push origin master:master
git checkout --detach
cd /tmp (or another other directory on your system)<br/>
git clone --bare /xcode-project-directory projectname.git<br/>
scp -r projectname.git sshusername@remotehost.com:repos/<br/>
cd /xcode-project-directory<br/>
git push sshusername@remotehost.com:repos/projectname.git<br/>
# initialization
git init --bare server/.git
git clone server content
git clone server local
# create crazy stuff
git commit -av
git push origin master
git pull
mkdir ..../remote
cd ..../remote
git clone --bare .../currentrepo/
git remote add remoterepo ..../remote/currentrepo.git
git push remoterepo master
git push production
mkdir mywebsite.git
cd mywebsite.git
git init --bare
#!/bin/sh
GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f
chmod +x hooks/post-receive
git remote add production git@myserver.com:mywebsite.git
git push production +master:refs/heads/master
git branch dev
git checkout dev
git push
git merge dev
machine1$ cd ..
machine1$ mv repo repo.old
machine1$ git clone --bare repo.old repo
A ← B
↑
[HEAD,branch1]
A ← B ← C
↑
[HEAD,branch1]
A ← B ← X
↑ ↑
[HEAD] [branch1]
[HEAD]
↓
C
↙
A ← B ← X
↑
[branch1]
git checkout -b some_tmp_name
git push
git checkout master
git branch -d some_tmp_name
heroku plugins:install https://github.com/heroku/heroku-repo.git
heroku repo:reset
git init
echo "line 1" > afile.txt
git add .
git commit -m ‘initial import’
git clone --bare . ../remote-repository.git
git remote add origin ../remote-repository.git
git push --set-upstream origin master
git clone //LJZ-DELLPC/remote-repository.git/ .
echo "line 2" > afile.txt
git add afile.txt
git commit -m 'added line 2'
git push
git pull
git push
lylez@LJZ-DELLPC ~
$ cd gitdir
/home/lylez/gitdir
lylez@LJZ-DELLPC ~/gitdir
$ ls
lylez@LJZ-DELLPC ~/gitdir
$ mkdir repo1
lylez@LJZ-DELLPC ~/gitdir
$ cd repo1
/home/lylez/gitdir/repo1
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git init
Initialized empty Git repository in /home/lylez/gitdir/repo1/.git/
lylez@LJZ-DELLPC ~/gitdir/repo1
$ echo "line 1" > afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git add afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git commit -m 'initial import'
[master (root-commit) f407e12] initial import
1 file changed, 1 insertion(+)
create mode 100644 afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git clone --bar . ../repo1-bare-clone
Cloning into bare repository '../repo1-bare-clone'...
done.
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git remote add origin ../repo1-bare-clone
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git push --set-upstream origin master
Branch master set up to track remote branch master from origin.
Everything up-to-date
lylez@LJZ-DELLPC ~/gitdir/repo1
$ cd ..
lylez@LJZ-DELLPC ~/gitdir
$ ls
repo1 repo1-bare-clone
lylez@LJZ-DELLPC ~/gitdir
$ mkdir repo1-remote
lylez@LJZ-DELLPC ~/gitdir
$ cd repo1-remote
/home/lylez/gitdir/repo1-remote
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ git clone ../repo1-bare-clone .
Cloning into '.'...
done.
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ ls
afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ cat afile.txt
line 1
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ echo "line 2" >> afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ git add afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ git commit -m 'added line 2'
[master 5ad31e0] added line 2
1 file changed, 1 insertion(+)
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 260 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /home/lylez/gitdir/repo1-remote/../repo1-bare-clone
f407e12..5ad31e0 master -> master
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ cd ../repo1
lylez@LJZ-DELLPC ~/gitdir/repo1
$ ls
afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1
$ cat afile.txt
line 1
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git pull
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ../repo1-bare-clone
f407e12..5ad31e0 master -> origin/master
Updating f407e12..5ad31e0
Fast-forward
afile.txt | 1 +
1 file changed, 1 insertion(+)
lylez@LJZ-DELLPC ~/gitdir/repo1
$ cat afile.txt
line 1
line 2
lylez@LJZ-DELLPC ~/gitdir/repo1
$ echo "line 3" >> afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git add afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git commit -m 'added line 3'
[master 3fa569e] added line 3
1 file changed, 1 insertion(+)
lylez@LJZ-DELLPC ~/gitdir/repo1
$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 265 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ../repo1-bare-clone
5ad31e0..3fa569e master -> master
lylez@LJZ-DELLPC ~/gitdir/repo1
$ cd ../repo1-remote/
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ ls
afile.txt
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ cat afile.txt
line 1
line 2
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ git pull
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/lylez/gitdir/repo1-remote/../repo1-bare-clone
5ad31e0..3fa569e master -> origin/master
Updating 5ad31e0..3fa569e
Fast-forward
afile.txt | 1 +
1 file changed, 1 insertion(+)
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ cat afile.txt
line 1
line 2
line 3
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
$ git --version
git version 2.1.1
lylez@LJZ-DELLPC ~/gitdir/repo1-remote
git branch shared_branch
repo1/.git/hooks (GIT_DIR!)$ cat update
#!/bin/sh
refname="$1"
oldrev="$2"
newrev="$3"
if [ "${refname}" != "refs/heads/shared_branch" ]
then
echo "You can only push changes to shared_branch, you cannot push to ${refname}"
exit 1
fi
git checkout -b my_work --track shared_branch
Branch my_work set up to track local branch shared_branch.
Switched to a new branch 'my_work'
git clone path/to/repo1 repo2
git checkout shared_branch
git init server
cd server
touch a
git add .
git commit -m 0
git config --local receive.denyCurrentBranch updateInstead
cd ..
git clone server local
cd local
touch b
git add .
git commit -m 1
git push origin master:master
cd ../server
ls
a
b
root@development:/home/git/repository/my-project# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[core]
repositoryformatversion = 0
filemode = true
bare = true
$ git remote show origin
* remote origin
Fetch URL: my-portal@development:/home/XYZ/repository/XYZ
Push URL: my-portal@development:/home/XYZ/repository/XYZ
HEAD branch: (unknown)
git remote show origin
HEAD branch: master
git pull; git push
git push origin master:foo
git merge foo
git push origin master -f
git config receive.denyCurrentBranch ignore
machine1:~/proj1> git init
machine2:~> git clone ssh://machine1/~/proj1
machine1:~/proj1> git config --bool core.bare true
machine1:~/proj1> mv .git/ ../proj1.git
machine1:~/proj1> cd ..
machine1:~> rm -rf proj1
machine1:~> git clone proj1.git
machine1:~> cd proj1
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[receive]
denyCurrentBranch = updateInstead
$ git config core.bare true
git push remote_repo // suppose the destination repo is remote_repo
$ git log -1
commit 0623b1b900ef7331b9184722a5381bbdd2d935ba
Author: aircraft < aircraft_xxx@126.com>
Date: Thu May 17 21:54:37 2018 +0800
$ git status
fatal: This operation must be run in a work tree
$ git config core.bare false
git push <remote> master:origin/master
! [remote rejected] development -> development (branch is currently checked out)