Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

a question about Bitbuket and git ignore


After trying from using the following:




The classes still get pushed up to bitbucket repository.

Did I miss out anything because I checked around and almost everyone said it is to be done like that.



2 answers

0 votes

Hi @nobodyIsMe,

Do you want to ignore all files with the extension .classes in your repo? Or files with the extension .classes from a certain directory of the repo?

Using *.classes should exclude all files with this extension, but I'm not sure what you are attempting to do with the pattern *.classes/folderName
Could you please clarify what you are trying to achieve?

Please keep in mind that if you had already committed in this repo any files with this extension before adding the .gitignore to the repository, these specific files will continue to be tracked. In this case, you will need to remove these files from the repo's history by rewriting history (I can share more details if you like) and then make sure that your repo has a .gitignore with the correct pattern.

Kind regards,

Hi Theodora,

I have changed it to *.classes already.

Now, I hope you could iron out my doubts regarding setting a global git ignore.

After watching a you tube video, I have put the git ignore at the C:\Users

Then, I did a git bash on the directory where my cloned repo branch lies :

git config --global core.excludefile ~/.gitignore - global.

Now, things get abit complicated when I realised that someone has checked in another change upstream.

So, I did a reset HEAD follows by a git stash to keep my changes.

After that, all the conflicts appear and I am lost.

I did a quick and dirty job by cloning another one.

However, after that, I am not able to make the project folder to git ignore the .classes again, even though I did all those above steps.

My question is if I still have something in the BitBucket repo, whatever I did, the .classes will still be uploaded is it ?

How do I make it such that my .classes won't be able to commit or can the administrator able to do some setting such that people won't be able to pull anything that has .classes inside ?

And did I miss out any steps that my global git ignore doesn't work ?


Hi @nobodyIsMe,

Location of .gitignore

You mentioned that you put the .gitignore file in C:\Users. However, the git config command uses ~/.gitignore and ~ is your home directory, which is normally C:\Users\MyUser on Windows (MyUser should be the name of your user on your computer).

I would suggest moving the .gitignore file in C:\Users\MyUser, and then from Git Bash you can execute this command

git config --global core.excludefile ~/.gitignore

Afterwards, check if the file is added by running the command

git config --global core.excludefile

Please note the following:

Setting a .gitignore globally on your machine prevents you from adding files specified in .gitignore in your repos.
It does not prevent your teammates from adding these files to their local clone.
In order to do that, you can do either of the following:

1. Either ask your teammate to set the same .gitignore globally on the machine they are working from
2. Or you add and commit the .gitignore in the repo. This way, when someone else takes a fresh clone of the repo, they'll have the .gitignore of this repo locally.


Removing committed files from the repo's history

If there are existing .classes in the repo (that were added before the .gitignore), you will need to remove them from the repo's history with a tool like BFG:

BFG has an option --delete-files (see documentation), so you can use it to delete all .classes files from the repo.
Please note that BFG rewrites history, which means that commit hashes will change. It's good to communicate this to your team so there are no surprises.
I also strongly recommend taking a backup of the repo (a clone with the --mirror flag, other than the one where you execute BFG), in case you want to revert the repo to the prior state.

In summary, my suggestions would be:

  • First, use BFG to remove the .classes files from the repo
  • Ensure you have set up correctly the global .gitignore, OR add the .gitignore to your repo
  • If you don't add the .gitignore to your repo, you'll need to ask all users who work on this repo to set the same .gitignore on their computer
  • After all these steps are completed, ask your teammates to take a fresh clone of the repo, in order to avoid pushing any of the old history that still contains the .classes files
  • Users can still add ignored files in the repo using the flags -f, --force in the git add command, so make sure you ask them not to use these flags when adding files to a repo.

Kind regards,

0 votes
Pramodh M Community Leader Jan 08, 2022

It will be pushed 

But these files will not be tracked via git, that's the whole purpose

To learn more about how .gitignore works go through the doc here



OK. I read in the tutorial that we can set it globally but it is using touch commands but I am using Windows 10.

So, I'd like to confirm is it done this way :

1. I will put *.classes/folderName in git ignore

2. then I do the following command

git config --global core.excludesFile ~/.gitignore the normal git add fileName

4. push

the classes/folderName won't get push up


Secondly, I'd like to clarify what do you mean by it won't be tracked and also if I do git config at that cloned project folder, will it just apply to that project only ? How do i make it ignore .classes/folderName throughout all the projects locally and it won't get push up to the repository.

Hope you could let me know.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

123 views 2 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you