29

I'm somewhat new applications with Ionic and very new to the subject of Git repositories. When I commit, endless files are uploaded - I find it very difficult to identify what changes are in the project.

So I wanted to ask for help here, is there a guide to ignore files if a file exists by default, and where, since most of the work is done in the www folder.

Sorry if the question is very basic, but I need help to solve this problem.

LightCC
  • 9,804
  • 5
  • 52
  • 92
NHTorres
  • 1,528
  • 2
  • 21
  • 39

5 Answers5

31

The problem here is that if you already add all those files, once you put the .gitignore it will not work as you want. You need to put the .gitignore at the very beginning of your project.

So, my advise: make another project in Git, just upload your project again and create the .gitignore file. I am telling you this based on my own experience.

The basics of what you should put in that .gitignore

node_modules
.tmp
.sass-cache
**/bower_components or sometimes it is lib/**
platforms
plugins
*.swp
*.swo
*.log
*.DS_Store

in order to create this file, you can do it from Git, or from your terminal:

  1. In Terminal, navigate to the location of your Git repository.
  2. Enter $ touch .gitignore to create a .gitignore file.
Non
  • 8,409
  • 20
  • 71
  • 123
  • 2
    Thank you very much for your help, the truth both answers helped me a lot! – NHTorres May 19 '15 at 15:57
  • @sioesi look, this is on the git help page: ```If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later.``` Exactly what I told you. [Here the reference](https://help.github.com/articles/ignoring-files/) – Non May 19 '15 at 16:08
  • 8
    There is no need to create a new project. To ignore files that have previously been committed use git `rm --cached`. See http://stackoverflow.com/questions/6535362/gitignore-after-commit – Doug Amos Jul 21 '15 at 16:33
  • 1
    @DougAmos the answer I provided is correct, yours is also correct. You don't have why to abuse of the Downvote functionality. You should use Downvote only when the answer doesn't make any sense or something like that, not in this case. – Non Jul 22 '15 at 22:57
  • @NietzscheProgrammer your answer is mostly correct, but is not recommended as any git history will be lost. This will be fine if not much work has been done, but not ideal if you have. Also a .gitignore file clearly does not have to be created at the begining of the project (I tried to remove my downvote, as you are right the answer will get the job done, but Stackoverflow wouldn't let me) – Doug Amos Jul 27 '15 at 19:40
  • If you are developing using Visual Studio 2015, you should add `bld/` and `[Bb]in/` too... – Rosdi Kasim Dec 19 '15 at 09:36
  • So its ok having resources folder versioned? – NBPalomino Sep 28 '17 at 19:50
  • It is completely incorrect to say "You need to put the .gitignore at the very beginning of your project." Add the correct .gitignore then simply delete the files, add the deletions to the index, commit, and all commits from that point on will not have the files and .gitignore works fine to keep them from showing up again. – LightCC Jul 25 '20 at 04:37
  • Hi @LightCC yeah. You are right. But you are wrong there saying "...then simply delete the files" since there is a proper command in order for the .gitignore file to grab the new changes. I will update my answer soon. – Non Jul 27 '20 at 18:52
  • I agree, [here is the correct answer](https://stackoverflow.com/a/20241145/6501141). Ran across this a while later. – LightCC Jul 27 '20 at 21:32
15

When using Ionic 2, the scaffolder (starter) project provides you a .gitignore file out of the box. It pretty much covers all the essential files that one wishes to untrack.

The .gitignore file present in your starter project should look like this:

# Specifies intentionally untracked files to ignore when using Git
# http://git-scm.com/docs/gitignore

*~
*.sw[mnpcod]
*.log
*.tmp
*.tmp.*
log.txt
*.sublime-project
*.sublime-workspace
.vscode/
npm-debug.log*

.idea/
.sass-cache/
.tmp/
.versions/
coverage/
dist/
node_modules/
tmp/
temp/
hooks/
platforms/
plugins/
plugins/android.json
plugins/ios.json
www/
$RECYCLE.BIN/

.DS_Store
Thumbs.db
UserInterfaceState.xcuserstate

For how to boot up a scaffolder Ionic 2 project, given that you have all the pre-requisite npm modules installed:

$ ionic start MyProject --v2

Inside the new directory MyProject/ created just now, you'll find the default .gitignore that comes with this starter/template project structure.

darkdefender27
  • 396
  • 1
  • 4
  • 15
4

You can use this gitignore

node_modules/
temp/
*.DS_Store
*.log
*.swp

For more details view this link http://forum.ionicframework.com/t/whats-a-good-gitignore-for-an-ionic-project/4115

Codelord
  • 1,120
  • 2
  • 10
  • 21
1

You can always use Ionic team's reference application and see how they configure .gitignore for the project:

https://github.com/ionic-team/ionic-conference-app

Here is the file: https://github.com/ionic-team/ionic-conference-app/blob/master/.gitignore

# Specifies intentionally untracked files to ignore when using Git
# http://git-scm.com/docs/gitignore
www/

*~
*.sw[mnpcod]
*.log
*.tmp
*.tmp.*
log.txt
*.sublime-project
*.sublime-workspace
.vscode/
npm-debug.log*
.firebase/
.idea/
.sourcemaps/
.sass-cache/
.tmp/
.versions/
coverage/
dist/
node_modules/
tmp/
temp/
hooks/
platforms/
plugins/
plugins/android.json
plugins/ios.json
$RECYCLE.BIN/

.DS_Store
Thumbs.db
UserInterfaceState.xcuserstate
Sergey Rudenko
  • 8,809
  • 2
  • 24
  • 51
0

If you use the Ionic CLI to create your project:

ionic start <name of project> blank <other options>

(This may not have been around when the Q was posted...)

It will have some .gitignore files included; However, if you want to look for additional files to exclude, you can look at GitIgnore.IO, and search for "Ionic". You may also want to look at files for your OS, IDE/editor, and other tools (i.e. "VisualStudioCode", etc.), to find additional files to add.

As mentioned in Non's answer, if you add the .gitignore after having made commits (per your question), you will get some strange behavior, because files already in the repo will continue to be tracked. You can use the command:

git update-index --skip-worktree <files>

To stop git from trying to track them, as explained in this answer. This shouldn't have any downsides, unless you eventually wish to track those files again, you will need to use git update-index --no-skip-worktree <files> to make them trackable again.

LightCC
  • 9,804
  • 5
  • 52
  • 92