0

I'm having some troubles with Git. I've got a project in Netbeans (Java) with plenty of csv and serialized files. I just want to push .java files on bitbucket.

Here's what I'm doing :

git cd myRepositoryPath
git add -A
git rm -r --cached csvFiles/
git rm -r --cached serializedFiles/
git commit -m "..."
git push

But when I do the push, there are still over a 1gb datas that are pushed on bitbucket.

It failed so many times that I tried this : git push origin +id_commit:master to get back to a former commit where everything was fine (no csv & serialized files on bitbucket) and now Git tells me that I'm "ahead of 'origin/master' by 2 commits".

I don't know what to do to make my repository clean again.

RobertB
  • 4,592
  • 1
  • 30
  • 29
zardlemalefique
  • 77
  • 1
  • 11

3 Answers3

3

You'll need to create .gitignore file with proper rules.

Example file:

/csvFiles/
/serializedFiles/

See documentation.

However it's important to note that git ignore won't affect files that you already commit into git (and therefore git already track them).

To tell git to ignore files specified in .gitignore that's already tracked you must use other commands: git rm --cached [file] or git update-index --assume-unchanged [file]. It depends what you really need. First one works for local repository so other people would need to maintain their local copy.

Also you may want to see this question.

Community
  • 1
  • 1
Konrad 'Zegis'
  • 15,101
  • 1
  • 16
  • 18
  • I did this and it's working, thank you very much ! Now it's only pushing the files I want. However, my repository is still too big (>1Gb) and I can't mannaged to reduce it size while using filter-branch. Any tips ? – zardlemalefique May 20 '16 at 11:00
  • @zardlemalefique The only thing that comes to my mind right now is using `git gc` command. See [documentation](https://git-scm.com/docs/git-clean) and [this](http://stackoverflow.com/questions/3162786/how-can-i-trigger-garbage-collection-on-a-git-remote-repository) question. Although I'm not sure if this would help in your case, sorry. – Konrad 'Zegis' May 20 '16 at 12:01
1

Gitignore will exclude directories or document routes from committing.

Also git cleanup, especially git prune will clean up old references. (Git pull,remove unnecessary data, commit/push, then gitignore and prune)

0

Add a gitignore file to exclude files you don't want to push, you can find the documentation over here: https://git-scm.com/docs/gitignore.

You can find some gitignore files here: https://github.com/github/gitignore.

Be aware that files that are tracked will also be tracked after the gitignore.

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked. To stop tracking a file that is currently tracked, use git rm --cached.

snijhof
  • 57
  • 1
  • 12