git push origin master not pushing the files

user3451003

I have setup my remote git and local git on my mac I was able to create a git repo (git init myrepo) on the remote machine (Linux) Added few files and committed them no problems (git add , git commit -m "test")

From my local I was able to clone the repo from the remote with no issues (git clone ssh://user@IP/Path)

So far so good no issues.

I have created few files locally and used git add and commit then tried to push them to the remote server using git push origin master

initially I received an error message and searching around the solution was to run this command directly on the remote server: git config receive.denyCurrentBranch ignore

That fixed the issues and now I am able to push successfully:

$ git push origin master

git add test.sh 
git add git*
git commit -m "Adding 2 new files and updating test.sh"
[master 4dd11a0] Adding 2 new files and updating test.sh
3 files changed, 109 insertions(+)
create mode 100644 gitHowToUrls.txt
create mode 100644 git_howto.txt
git push origin master
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.91 KiB | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To ssh://root@IP/path/myrepo
ad4a8b2..4dd11a0  master -> master

$ git push -u origin master

Branch master set up to track remote branch master from origin.
Everything up-to-date

$ git push origin HEAD:master

Everything up-to-date

I even checked to make sure that the files match

$ git ls-remote origin

52543130bff4f9f37a23b01b0c44c7549ab82dd9        HEAD
52543130bff4f9f37a23b01b0c44c7549ab82dd9        refs/heads/master

$ git ls-remote

From ssh://root@IP/path/myrepo
52543130bff4f9f37a23b01b0c44c7549ab82dd9        HEAD
52543130bff4f9f37a23b01b0c44c7549ab82dd9        refs/heads/master

However when I go to my remote repo (root@IP/path/myrepo) I can't see any of the new files!!! Any idea what I am doing wrong?

I ran git log on the remote server and I see all my notes:

root@IP [myrepo]# git log
 commit 52543130bff4f9f37a23b01b0c44c7549ab82dd9
Author: joe d <myemail@myemail>
Date:   Sat Mar 22 15:56:30 2014 -0700

    adding again, since first time didn't work

 commit 4dd11a0235cdabe528f8755253989ce85df4fa8b
Author: joe d <myemail@myemail>
Date:   Sat Mar 22 15:48:08 2014 -0700

    Adding 2 new files and updating test.sh

 commit ad4a8b224989dc2131b6a33f41b95ce8b2a5c96a
Author: joe d <myemail@myemail>
Date:   Sat Mar 22 11:33:34 2014 -0700

   test

 commit 956ff16e081587fa59a8cec73fc383744c5c3a5e
Author: joe d <myemail@myemail>
Date:   Sat Mar 22 18:32:30 2014 +0000

    test

My remote repo:

root@IP [myrepo]# ls -la
total 20
drwxr-xr-x 4 root    root    4096 Mar 22 18:32 .
drwxr-x--- 6 joe nobody  4096 Mar 22 18:30 ..
drwxr-xr-x 8 root    root    4096 Mar 22 18:38 .git
drwxr-xr-x 2 joe joe 4096 Mar 21 22:12 images
-rw-r--r-- 1 root    root     992 Mar 22 18:31 index.html

My local repo:

localmachine:myrepo joe$ ls -la
total 32
drwxr-xr-x   8 joe  1668562246   272 Mar 22 16:42 .
drwxr-xr-x   3 joe  1668562246   102 Mar 22 11:33 ..
drwxr-xr-x  15 joe  1668562246   510 Mar 22 16:07 .git
-rw-r--r--   1 joe  1668562246   445 Mar 22 16:42 gitHowToUrls.txt
-rw-r--r--   1 joe  1668562246  3291 Mar 22 15:56 git_howto.txt
-rwxr-xr-x   1 joe  1668562246    81 Mar 22 15:43 test.sh
drwxr-xr-x   6 joe  1668562246   204 Mar 22 11:33 images
-rw-r--r--   1 joe  1668562246   992 Mar 22 11:33 index.html

Thanks

NEW NOTE:

OK, so I wasn't using bare branch for sure, I think its the command I ran on the remote system

git config receive.denyCurrentBranch ignore

I have deleted both repos on local and remote and created it again (No bare for sure)

Then attempted a push like so and received this error:

localrepo$ git push origin master
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.98 KiB | 0 bytes/s, done.
Total 5 (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://root@IP/path/myrepo
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://root@IP/path/myrepo'

This time round I entered refuse instead of ignore

git config receive.denyCurrentBranch refuse

Running git push generated a new error message:

localRepo$ git push origin master

Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.98 KiB | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
To ssh://root@IP/path/myrepo
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://root@IP/path/myrepo'

How do I uncheck the branch so I could successfully push from local to remote repo?

VonC

You are pushing to a non-bare repo (which works because of the receive.denyCurrentBranch being set to ignore).

But it it possible that your remote non-bare repo:

  • has checked out a different branch than master (and since you are pushing to master, the content of the working tree wouldn't change)
  • or has checked out a commit (meaning you are in a detached HEAD state, which you can confirm with a git branch inside that repo, to see if any of those branches is marked as checked out or not).

I have deleted both repos on local and remote and created it again (No bare for sure)

By default, receive.denyCurrentBranch is set to 'refuse', so your error messages are consistent with that.

Try setting it on 'ignore', and since your remote repo is on master, your push will go through.

But you won't see any file: you need a post-receive hook which would checkout your working tree or reset it to HEAD, for the files to actually appear.

See for instance "Git: making pushes to non-bare repositories safe"

my post-receive hook looks like this:

export GIT_WORK_TREE=..
git checkout -f HEAD

The OP reports in the comments:

the answer to the original issue is run this on the remote server:

git config receive.denyCurrentBranch ignore 

Then Add export GIT_WORK_TREE=.. git checkout -f HEAD To your gitrepo <PATH>/.git/hooks/post-receive

That did the trick and I am now able to push files from my local to the remote repo!!!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

git push origin master not pushing the files

From Dev

How can I push certain files to origin/master in Git?

From Dev

Git: git push -u origin origin:master

From Dev

GIT: cannot push to origin/master

From Dev

'git push origin master' freezes

From Dev

Git push origin master issue

From Dev

Git push not creating remote branch, pushing to master

From Dev

git push origin master = permission denied ( publickey )

From Dev

git push origin branchname always pushes to master

From Dev

git push origin branchname always pushes to master

From Dev

`git push origin master` does not work

From Dev

Push Commit origin:master with git (android studio)

From Dev

What is the difference between "git push" and "git push origin master"?

From Dev

Git failure in uploading using "git push origin master"

From Dev

Difference between origin master & origin/master with git pull and git push commands

From Dev

Gitlab push origin master

From Dev

Webstorm Git new remote repository: Push to origin/master was rejected

From Dev

Why did git push origin master draw ASCII art?

From Java

What does the -u flag mean in git push -u origin master?

From Dev

Why "git push origin master" doesn't work?

From Dev

git push origin master: permission denied (public key) error

From Dev

2 errors produced by git push -u origin master

From Dev

git push origin master: permission denied (public key) error

From Dev

Why "git push origin master" doesn't work?

From Dev

How to check if I have Push permission in Git Master branch origin?

From Dev

What does the -u parameter mean in git push -u origin master?

From Dev

Pushing to +master versus force push

From Dev

Can I use git push origin master:myBranch to push code I modified in master branch to my branch?

From Dev

What is origin/master in git compared to origin master?

Related Related

  1. 1

    git push origin master not pushing the files

  2. 2

    How can I push certain files to origin/master in Git?

  3. 3

    Git: git push -u origin origin:master

  4. 4

    GIT: cannot push to origin/master

  5. 5

    'git push origin master' freezes

  6. 6

    Git push origin master issue

  7. 7

    Git push not creating remote branch, pushing to master

  8. 8

    git push origin master = permission denied ( publickey )

  9. 9

    git push origin branchname always pushes to master

  10. 10

    git push origin branchname always pushes to master

  11. 11

    `git push origin master` does not work

  12. 12

    Push Commit origin:master with git (android studio)

  13. 13

    What is the difference between "git push" and "git push origin master"?

  14. 14

    Git failure in uploading using "git push origin master"

  15. 15

    Difference between origin master & origin/master with git pull and git push commands

  16. 16

    Gitlab push origin master

  17. 17

    Webstorm Git new remote repository: Push to origin/master was rejected

  18. 18

    Why did git push origin master draw ASCII art?

  19. 19

    What does the -u flag mean in git push -u origin master?

  20. 20

    Why "git push origin master" doesn't work?

  21. 21

    git push origin master: permission denied (public key) error

  22. 22

    2 errors produced by git push -u origin master

  23. 23

    git push origin master: permission denied (public key) error

  24. 24

    Why "git push origin master" doesn't work?

  25. 25

    How to check if I have Push permission in Git Master branch origin?

  26. 26

    What does the -u parameter mean in git push -u origin master?

  27. 27

    Pushing to +master versus force push

  28. 28

    Can I use git push origin master:myBranch to push code I modified in master branch to my branch?

  29. 29

    What is origin/master in git compared to origin master?

HotTag

Archive