On Tue, Mar 7, 2017 at 3:16 PM, Sanjeev Sariya <sanjeevsar...@gmail.com>
wrote:

> Hello There,
>
> I'm new to git and trying to get learn basic features. I've server on
> remote local which has code. I'd refer to it as *server*.
> Am on my local machine from which I'd edit the code. I'd refer to it as
> *local*.
>
> On server I create new directory and do
>
>  git init
>
>
​Here's your problem. You've created a "normal" repository. What you really
need is a "bare" repository. What I suggest is to do the following on the
SERVER

cd <to the new directory>
rm -rf .git # remove normal git stuff
git init --bare #create a bare repository

A bare repository only contains the repository information. That is, it
does _NOT_ have any user files in it.​



>
> I add file and commit it to git.
>
> Next, I add id_pub to authorized key.
>
> On local I create new directory and do
>
> git init
>
>
> Go to local add remote
>
> git remote add origin ssh://user-name@server_IP_address:path/git/alphatest
>>
>
>
>
> I do git fetch/pull to get file. I modify it, add and commit it to git.
> Things go fine until then. However, when I try to push it using
>
> git push -u origin master
>
> or
>
> git push origin master
>
> or
>
>> git push
>
>
> None of these work. I get following error with 2nd command.
>
> Error:
>> Writing objects: 100% (3/3), 267 bytes | 0 bytes/s, done.
>> Total 3 (delta 0), reused 0 (delta 0)
>> 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 to
>> remote: error: 'ignore' or 'warn' in the remote repository to allow
>> pushing into
>> 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 some
>> remote: error: other way.
>> remote: error:
>> remote: error: To squelch this message and still keep the default
>> behaviour, set
>> remote: error: 'receive.denyCurrentBranch' configuration variable to
>> 'refuse'.
>> To ssh:// ! [remote rejected] master -> master (branch is currently
>> checked out)error: failed to push some refs to 'ssh:'
>
>
>
>> Counting objects: 3, done.
>
> However, on *local* if I do
>
> git push origin master:*foo*
>
>
> And on *server* I do
>
> git merge *foo*
>
>
>  Things work fine.
>
> I'm unable to understand what is going wrong and why I've to add branch. I
> found the solution from SO link
> <http://stackoverflow.com/a/32870283/2740831>.
>
> Any help shall be great.
>

​Well, unless you plan to edit files on the SERVER, then you really need a
__bare__ repository. ref:
https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server

The basic reason is that a "regular" (non-bare) repository is meant to have
a "working directory" in which some user is actively modifying files. Now,
imagine if another person did a "git push" into their repository in the
active branch. All of a sudden, all the user's edits are out-of-sync with
what s?he thinks it should be. This causes (him|her) problems when they try
to "git commit" because the files in their repository don't reflect the
history of the files in their directory. so they'd need to do a merge and
resolve any conflicts. It's just not the way git was designed to work. I
wish I were a better teacher, but hopefully the URL I gave earlier will be
helpful.
​



>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Git for human beings" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to git-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"Irrigation of the land with seawater desalinated by fusion power is
ancient. It's called 'rain'." -- Michael McClary, in alt.fusion

Maranatha! <><
John McKown

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to