162

I'm trying to git push -u origin master And it just hangs at

Writing objects:  99% (219/220), 12.65 MiB | 97 KiB/s

The 12.65 part shifts around. When I exit the process and run it again, it resumes at 99% but never finishes, same as before.

It's never pushed successfully. This is the initial commit.

mattalxndr
  • 9,143
  • 8
  • 56
  • 87
  • Where do you want to push to? Are you using SSH or some other protocol? – Paŭlo Ebermann Jul 31 '11 at 03:01
  • 34
    Would setting the `http.postbuffer` help? http://stackoverflow.com/questions/6842687/the-remote-end-hung-up-unexpectedly-while-git-cloning/6849424#6849424 – VonC Jul 31 '11 at 06:55
  • 4
    VonC's comment is too easy to overlook. It works for me. – Thuan Mar 10 '14 at 13:36
  • 1
    Unbelievable. That did it for me, too. And it's 2018 now. And it's SSH, not HTTP. And the whole repo is like 15MB. And the "remote" server is localhost. Stop romanticizing Git, folks, please! ;) – Sz. Mar 02 '18 at 23:51

10 Answers10

374

I followed VonC's advice:

git config --global http.postBuffer 524288000

For future references, based on comments:

500 MB: 524288000 (as posted in the original answer)
1 GB: 1048576000
2 GB: 2097152000 (anything higher is rejected as 'out of range')
Community
  • 1
  • 1
Hugo Forte
  • 5,718
  • 5
  • 35
  • 44
  • on the client or on the server? – wutzebaer Jul 28 '15 at 19:24
  • On the client @wutzebaer – Hugo Forte Jul 30 '15 at 20:19
  • 7
    @HugoForte Increasing the buffer seemed to resolve my hanging writing of files, but my git push never completed (hung after `Writing objects: 100%`) -- previously it was hanging at 25% so this clearly helped. However, I was still getting "weird" behavior. I **restarted my system** and this seemed to resolve things...FYI...if anyone is still hitting issues after increasing their buffer, restarting my system helped in my situation (old school solution none the less but a fresh restart really helped). – twknab Mar 23 '17 at 16:59
  • 2
    @twknab even after restarting my system, the push is not completing. Do you have any solution for this? – Shivani Bajaj Apr 10 '21 at 07:03
  • @HugoForte I tried but after write finish it stucks – masoud anaraki Mar 03 '23 at 11:13
46

This was happening because of huge, unignored file in the repo directory. Whoops.

EDIT

The hang was because the file was taking a long time to upload. The file wasn't supposed to have been included in the push.

EDIT

While it's true that a huge file could be the reason behind this issue, if you can't ignore the file in question or just have to push it then follow this answer.

pavanlimo
  • 4,122
  • 3
  • 32
  • 47
mattalxndr
  • 9,143
  • 8
  • 56
  • 87
  • @TimoSolo Why would I do that? I was the one with the issue, and I documented the exact fix. Pretty straightforward. – mattalxndr Mar 07 '18 at 17:00
  • 6
    Yes, your fix was to remove the problem. For the sake of other people who actually need to push a large file, @hugo-forte's answer solves the problem. You don't *have* to, I just thought it would help more people - in the spirit of SO. – TimoSolo Mar 08 '18 at 09:03
  • 2
    The question is not "How can I commit, then push a huge file?". It's "My git push is neverending. Why?" If you aren't expecting the push to take forever, then you probably (like me) didn't mean to commit that huge file. – mattalxndr Mar 08 '18 at 20:40
  • 4
    @mattalxndr When the accepted answer has 1/8 the votes, you should probably change it. – NorCalKnockOut Mar 28 '18 at 22:32
  • @NorCalKnockOut Ignoring the people with the weird problem that actually prompted me to ask the question in the first place? That's doesn't make sense to me. – mattalxndr Apr 04 '18 at 22:46
  • 1
    @mattalxndr Neither answer is perfect. One identifies the cause, and the other offers a solution. The ideal answer would identify the cause, explain why it has the given result, and offer the two alternative solutions. IMO, out of the current options, Hugo Forte's answer is superior because it will solve the problem regardless of whether you meant to push the file or not. It's not ignoring the people who made the same mistake you did; it fixes the problem for them just as much as anyone else, but leaves it to them to remove a file if they didn't intend to push it. – Zac-K Jul 19 '18 at 00:25
  • "Hugo Forte's answer is superior because it will solve the problem regardless of whether you meant to push the file or not." I see your point there. Changed to @Hugo's answer. – mattalxndr Jan 04 '22 at 00:01
12

I had the same problem with (writing objects %16) stuck then fatal. I solved this by saving the current changes and clone a new repository, then copy the modified files into it.

Eg. Assume current repository is A, then all you need to do is:

  1. mv A B
  2. git clone A
  3. mv B/* A/
  4. rm -rf B

Then commit and push and it all worked fine. It recognized the moved files as modified :)

iwein
  • 25,788
  • 10
  • 70
  • 111
Maha
  • 180
  • 1
  • 6
6

In my case, I was using a git folder with bad rights stored on the same drive as a repo, but it could be the same with ssh even if you use an authorized login user.

Check then if you have correct rights to write on the distant repo.

Example:

Init local and distant repo

git init /tmp/src
git init --bare /tmp/dst
cd /tmp/src

Adding remote repo to origin

src > git remote add dest /tmp/dst

Simulating problem

src > chmod -R 555 /tmp/dst

Adding fake file and pushing it

src > touch a && git add a && git commit -m 'demo'
src > git push --set-upstream dest master
src > git push
Counting objects: 3, done.
Writing objects: 99% (2/3), 202 bytes | 0 bytes/s.

Git hangs

Solution

src > chmod -R 775 /tmp/dst
Naewis
  • 96
  • 1
  • 4
3

In my situation it was the size of the file. By adding an .gitignore file with the required extensions I was able to ignore most of the unwanted files to be pushed.

Skitty
  • 1,709
  • 18
  • 21
2

git clean -f -n solves my issue. There are many untracked files not detected. But be careful because this will remove files in your directory

Anonymous Duck
  • 2,942
  • 1
  • 12
  • 35
  • 10
    Specifically which files will it remove? – Jazimov Sep 18 '18 at 17:12
  • 1
    `git clean` gets rid of any uncommitted files. The `-f` flag forces the command to run, and the `-n` makes it a dry run and tells you which files will be removed. So... You'll see which files get deleted. So actually, @Jazimov, you're undoing the -n flag by having the -f flag ahead of it. https://git-scm.com/book/id/v2/Git-Tools-Stashing-and-Cleaning#_git_clean – unixcorn Nov 14 '22 at 15:44
  • @unixcorn right, been years since I'm answering questions and comments – Anonymous Duck Nov 30 '22 at 12:55
  • I had no uncommited files but there were large files went with a commit and then deleted with next commit. It was hanging, and after running this cmd it pushed right away. Thanks! – a.t. yilmaz Feb 12 '23 at 15:14
2

In my case I was having slow internet upload speed and the file I wanted to push was big, the trick is to use git LFS (large file storage) that is much more patient to upload big files, you can find a git LFS tutorial here

Oscar Lima
  • 109
  • 1
  • 3
2

For Iranian

Unfortunately, due to severe disruptions in the Internet in Iran, the only method that worked for me was using a DNS changer that came from the Ministry of Cut of Communications.

Masih Jahangiri
  • 9,489
  • 3
  • 45
  • 51
1

In my case, I was trying to push without completing my company's rules. I learnt later that we should start our commit messages with "MOBIL-XXXX" where XXXX is the number developers are assigned in Jira (another tool we use to track development process) by analists.

Make sure to check if your company has a similar constraining rule.

Onat Korucu
  • 992
  • 11
  • 13
1

I was having the same issue on Windows 10 machine, the writing objects was hanging, but in a little different situation.

The problem I was having was only when I was trying to add new files to the repository. If I update files which are already existing in the repository everyting was working fine and it doesn't really matter if the file size was big or not. Mostly I was trying to add new scripts.

I tried every other solution found in the internet but nothing worked in my case and the last thing which I tried actually worked. It seems that it was because of some Windows permissions for the specific drive and folder which prevents the app's from writing in those specific folders or update the files even when I am logged in with an admin account and was running the app as admin. So this command:

attrib -r +s D:\foldername 

fixed the issue for me.

Just posting it here, maybe someone have the same issue as mine.

hardartcore
  • 16,886
  • 12
  • 75
  • 101
  • Not only windows! I had the same problem when admin had forgot to give me any permissions to put my files to remote repo. Why no errors? – Wera Feb 21 '22 at 09:27