简体   繁体   中英

Git pushing to correct remote repo?

In my shared host directory I have a flask app in a git directory:

username@so6 [~/domains/mi]# ls -la
total 88
drwxr-xr-x  7 username username 4096 Jun 28 12:30 ./
drwxr-xr-x 19 username username 4096 Jun 28 12:30 ../
-rw-rw-r--  1 username username   59 Jun 28 12:30 .bowerrc
drwxrwxr-x  5 username username 4096 Jun 28 12:30 .git/
-rw-rw-r--  1 username username  400 Jun 28 12:30 .gitignore
drwxrwxr-x  3 username username 4096 Jun 28 12:30 .idea/
-rw-rw-r--  1 username username 8192 Jun 28 12:30 dev.db
-rw-rw-r--  1 username username 2528 Jun 28 12:30 manage.py
drwxrwxr-x  3 username username 4096 Jun 28 12:30 migrations/
drwxrwxr-x  8 username username 4096 Jun 28 12:30 myflaskapp/

I want to push changes from it from my local copy so I tried:

$ git push shared master
username@mydomain.net's password:
stdin: is not a tty
Counting objects: 28, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (21/21), 3.47 KiB | 0 bytes/s, done.
Total 21 (delta 17), 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://username@mydomain.net:/home/username/domains/mi/.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://username@mydomain.net:/home/username/domains/mi/.git'

reading up on the error message I was going to pull then push , I tried:

$ git pull shared master

From ssh://mydomain.net:/home/username/domains/mi/
 * branch            master     -> FETCH_HEAD
Already up-to-date.

Now I'm wondering if my remote url is set correctly. shared is set to 'ssh://username@mydomain.net:/home/username/domains/mi/.git' , does this seem right?

BTW, I ran a

~/domains/mi git reset --hard

Then tried to push again. No change , I'm getting same error.

edit:

$ git remote show shared
user@domain.net's password:
stdin: is not a tty
* remote shared
  Fetch URL: ssh://username@domain.net:/home/user/domains/mi/.git
  Push  URL: ssh://username@domain.net:/home/user/domains/mi/.git
  HEAD branch: master
  Remote branch:
    master new (next fetch will store in remotes/shared)
  Local ref configured for 'git push':
    master pushes to master (fast-forwardable)

You are trying to change head branch of a non-bare repository. Usually remote repositories are bare which means that it has no working tree, because nobody works on it directly, but only push branches to it.

To check which repository

git remote show shared

To push to a different (non-current) branch on shared (master1)

git push shared master:master1

or you can go to the 'shared' and change it's current branch or make the whole repository bare.

If you have your global config set to accept your ssh key for authentication, you shouldn't be using your username for the URL. you should be using the git user. You should also have a port number after the colon, as that is how the system is accessed via ssh. Given that your port number is 8080 , try this: ssh://git@mydomain.net:8080/home/username/domains/mi/project_name.git .

You typically want the project name in the URL as well, not just the .git at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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