2012-01-24 10 views
54

Voglio memorizzare le mie modifiche locali a JBoss config in git. Per questo, ho istituito la seguente struttura:git push fallisce: `rifiuto di aggiornare il ramo estratto: refs/heads/master`

lrwxrwxrwx 1 jboss jboss  19 Jan 24 11:53 current -> jboss-as-7.1.0.CR1b 
drwxr-xr-x 11 jboss jboss  4096 Jan 24 12:13 jboss-as-7.1.0.CR1b 
-rw-r--r-- 1 jboss jboss 108211143 Jan 23 16:02 jboss-as-7.1.0.CR1b.tar.gz 
drwxr-xr-x 6 jboss jboss  4096 Jan 24 11:36 local 

local è il repository git, che sarà la "origine". L'idea è che voglio essere in grado di aggiornare facilmente la mia distribuzione JBoss una volta disponibile un aggiornamento. Voglio memorizzare tutte le modifiche locali al pacchetto JBoss distribuito in git.

Quindi, attualmente faccio questo:

[email protected]:~/jboss-as-7.1.0.CR1b$ git init 
Initialized empty Git repository in /opt/jboss/jboss-as-7.1.0.CR1b/.git/ 
[email protected]:~/jboss-as-7.1.0.CR1b$ git remote add origin ../local/ 
[email protected]:~/jboss-as-7.1.0.CR1b$ git pull origin master 
From ../local 
* branch   master  -> FETCH_HEAD 

Fin qui tutto bene, tutte le mie modifiche locali ci sono dove voglio.

Tuttavia, una volta che ho modifiche locali e voglio Bush di nuovo nel repository local, ottengo un errore:

[email protected]:~/jboss-as-7.1.0.CR1b$ vim standalone/configuration/standalone.xml 
[email protected]:~/jboss-as-7.1.0.CR1b$ git commit -a -m "renamed database to project2_core, to distinguish from other projects" 
[master 3e54f34] renamed database to project2_core, to distinguish from other projects 
Committer: jboss <[email protected](none)> 
1 files changed, 1 insertions(+), 1 deletions(-) 

[email protected]:~/jboss-as-7.1.0.CR1b$ git push origin master 
Counting objects: 9, done. 
Compressing objects: 100% (4/4), done. 
Writing objects: 100% (5/5), 447 bytes, done. 
Total 5 (delta 3), reused 0 (delta 0) 
Unpacking objects: 100% (5/5), done. 
remote: error: refusing to update checked out branch: refs/heads/master 
remote: error: By default, updating the current branch in a non-bare repository 
remote: error: is denied, because it will make the index and work tree inconsistent 
remote: error: with what you pushed, and will require 'git reset --hard' to match 
remote: error: the work tree to HEAD. 
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable t 
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int 
remote: error: its current branch; however, this is not recommended unless you 
remote: error: arranged to update its work tree to match what you pushed in som 
remote: error: other way. 
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, se 
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. 
To ../local/ 
! [remote rejected] master -> master (branch is currently checked out) 
error: failed to push some refs to '../local/' 

Cosa posso fare? Qualsiasi aiuto è molto apprezzato!

EDIT

Ecco quello che ho fatto, che ha risolto il problema:

cd ~/current 
git init 
vim .gitignore     # set up a basic .gitignore file 
git add .gitignore 
git commit -a -m "initial commit" 
cd ~/local 
git clone ~/current 
git branch -m master current  # rename master branch to 'current' 
git branch repo 
git checkout repo 

Ora, il ramo current nella directory ~/local è sempre up-to-date, ma non è cheked fuori, in modo che posso spingere in esso.

+3

possibile duplicato del [errore git push '\ [respinto remote \] maestro -> master (il ramo è attualmente estratto) '] (http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked) –

risposta

57

Il ramo principale del sito remoto è stato estratto. Se hai accesso al repository remoto, controlla qualsiasi altro ramo e poi spinga dal tuo repository.

+1

grazie, questo mi ha indirizzato nella giusta direzione. aggiornato il mio post per dare la soluzione completa. –

+1

Ma puoi dare qualche comando ..? E se avessi un solo ramo ..? repository remoto è nuda. – shashwat

+0

@vpatil. La stessa domanda qui. Voglio essere in grado di inviare una nuova filiale – SearchForKnowledge

66

Il push è pensato per i reposli nudi. Per i repository non nudi dovresti inserirli.

Se si desidera forzare questo passaggio, è possibile eseguire come indicato nel messaggio di errore e impostare receive.denyCurrentBranch in modo che ignori. SSH per la posizione del pronti contro termine si stanno spingendo a ed eseguire:

git config receive.denyCurrentBranch ignore 
+1

Penso che questo sia un approccio migliore rispetto a un ramo diverso. – jjmontes

+1

Sto usando sourcetree. Dove apporto le modifiche? – SearchForKnowledge

14

Creare l'origine repository (locale) come un repository nudo (cioè git init --bare.), O alla partenza una filiale in là, che è non padrone.

1

Sono riuscito a aggirare questo tirando da "locale" in "corrente" piuttosto che spingendo a "corrente" da "locale".

12

O,

quando si inizializza il progetto a distanza, utilizzando

git init --bare 
+0

Lo farò. In qualche modo ho dimenticato quando ho creato il repository remoto che questo è il modo per farlo. –

1

So che questo è piuttosto una vecchia questione, ma se si va con git init --bare, guardare fuori per 'GIT_DIR = '. che verrà impostato per un gancio repo nudo se si utilizzano ganci per il checkout dopo il push. Usa 'export GIT_DIR = .git' nella tua routine di hook per far sì che riconosca il repository che stai inserendo ....

0

remoto è possibile git checkout -b myTempBranch
locale         e poi git push
remoto poi finalmente git checkout master