Skip to content
Advertisement

How can I push only the files in current index?

I have many large binary files with source code under git version control.

I want to only push the source files to github for repo initialization.

So I used git rm -r --cached to remove the large binary files from the index.

After checking git ls-tree -r --names-only mybranch, I confirmed there are only text source files in the index.

When I then pushed to github, git checked 3 thousand files to transfer, and started pushing about 1GB content to remote github. But those source files together occupy merely 53KB.

From the logs I found that the binary files in historic commits were being pushed to remote.

Is there an option that only pushes my current index? like :

git push --depth 1

Thanks in advance for any advice.

Advertisement

Answer

You have a few options here.

A simple approach, If you are happy to re-initialise your git repo and “start-fresh”, is to just delete your .git folder and re initialise it:

  • rm -rf .git
  • git init
  • git add ...
  • git commit -m"..."

Only add the files you want (not the binaries) – infact add the binaries to the .gitignore file, e.g. if they are all called x.out, y.out, z.out then you can add the following to your .gitignore:

  • *.out

Or if they are all in some output folder you can add the following to your .gitignore:

  • outputfolder/

If you want to re-add your remote then you can do the following:

git remote add origin <remote-url>

update

If you need over-write your remote then you can use:

git push -f origin master

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement