1

I set up an online project in the yii2 framework on my local and started maintaining the code using Git. A few days later I decided to ignore a few files & folders like "vendor, runtime and upload" folders. I have 3-5 git branches now. I also created a repository in Github website for saving my changes online. But, all the ignored files & directory are getting pushed to GitHub. The total directory size (excluding .git directory) is around 632MB. The '.git' directory itself is 1.3 GB.

I don't want to push the ignored files and directories.

I used the following command to remove already added files & folders from Git.

git rm --cached <file> 
git commit -m "to save the changes"

But when I push the files to the server, it still pushes stagged and ignored files & directories.

I want to permanently ignore the files & directories I added in the '.gitignore' file from all my Git branches and also want to push rest of the files in Git. Here is the copy of my Git ignore file. Every time I use the following command, it adds the ignored files as well.

git add --all *

The Git ignore file:

# windows thumbnail cache
Thumbs.db

# composer itself is not needed
composer.phar

# composer vendor dir
/protected/vendor

# runtime dir
/protected/frontend/runtime/
/protected/backend/runtime/

#tempfiles
*~
/assets/**
/uploads/*
*.log

@Drubio Here's the directory structure:

/assests
/uploads
/protected
    /backend
       /runtime
       /<rest all the directory by default installed with yii2
    /common
    /frontend
       /runtime
       /<rest all the directory by default installed with yii2
    /vendor
    /console
    /environment

/.git
<few files here on root>
.gitignore
.htaccess

Please help.

Thanks

Curious Developer
  • 705
  • 3
  • 9
  • 29
  • 1
    Is your .gtiignore in the top level of your project directory? – dimwittedanimal Jan 18 '19 at 13:46
  • 1
    The directory tree would be helpful to see if we can help you. – Drubio Jan 18 '19 at 14:15
  • 1
    When you say that you're pushing them, are they in your tree in the current commit? Or are you pushing historical versions of them? ie, do you _see_ them on GitHub? Or are you noticing that it's pushing 1.4 GB and that's the problem? – Edward Thomson Jan 18 '19 at 16:22
  • @dimwittedanimal yes my ".gitignore" file it in the top level of my project directory. – Curious Developer Jan 19 '19 at 05:29
  • @Drubio Now sure how the directory structure is going to help but, I will add it anyways. – Curious Developer Jan 19 '19 at 05:30
  • @EdwardThomson I was trying to push the history version earlier i.e. my master branch. It never worked, but now I am trying to push my current branch. My current branch have files about 475MB (including the vendors and runtime folder) and including uploads its 632MB and my '.git' directory size is 1.3 GB. I am noticing the size being pushed in the Git. I am not yet succeeded to push any of the branches on the GitHub server. – Curious Developer Jan 19 '19 at 05:35
  • @Drubio I have added the directory structure in my question description. – Curious Developer Jan 19 '19 at 06:45

2 Answers2

0

so the problem is that your ignored files were already pushed to the remote branhc try the following set of commands:

to see the unwanted files:

git ls-files -ci --exclude-standard

remove the unwanted files

git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached

commit the changes

git commit -am "Removed unwanted files"

push the changes:

git push origin <branchname>

Community
  • 1
  • 1
dalton
  • 11
  • 1
  • 4
  • Isn't the `git ls` commands for git large files repository? None of my file sizes more than 5MB. – Curious Developer Jan 19 '19 at 06:51
  • the `git ls-files` command is similar to `ls` on your terminal, used to show information about files in the index and the working tree check here for details: https://git-scm.com/docs/git-ls-files – dalton Jan 21 '19 at 13:59
  • Thanks for your reply @dalton. My branch is not yet added to Git, I am currently maintaining the code and branches on my local and not able to push the branch on the Git. – Curious Developer Jan 23 '19 at 04:49
0

Removing the unwanted files using git rm will remove those files from the file-tree in the commit where you removed them, but it will not make the Git repo smaller, since Git keeps a history of all the old commits still in the repository, and therefore of all the files they contain.

I don't want to go into how to rewrite the history to remove those large files - that's discussed at length here: How to remove/delete a large file from commit history in Git repository? but if you just started using Git for this project, it might be easiest to start with a fresh repo.

joanis
  • 10,635
  • 14
  • 30
  • 40