What files for an MEAN project should I send to Github?

Asked

Viewed 542 times

5

I created an MEAN project in MVC and I’m willing to put it on Github, but I’m not sure what to send. If I try to send the whole folder it makes a mistake saying that there are more than 2,000 files because of Nodejs, Bower, etc. So what files are really needed to send to Github?

3 answers

3


NPM and Bower folders do not need to be uploaded to the repository. This is one of the advantages of using a package manager.

To ignore these files, you need to create a file .gitignore at the root of the project.

The contents of the file should be something like:

/node_modules/
/bower_components/

3

First, have the Git installed and configured on your machine.

As you mentioned, your project has many packages. When using a package manager it is not necessary to send the packages to the repository due to the file containing the list of all packages and dependencies used. In most managers this file is the package.json.

To prevent packages from being sent, create a file called .gitignore. The contents of this file will define which folders and files should not be sent to version control. This varies from environment to environment and from project to project.

On Mac, for example, in all folders a file is created .DS_Store, that has some file explorer parameters. This is an example of a file that should not be sent to Git.

Another situation is some text editors or Ides, such as Visual Studio Code, which creates a folder .vscode with the specific editor/IDE settings for your project. One more that shouldn’t be sent.

Let me give you an example of .gitignore as I would in an environment like yours:

/vendor/
/node_modules/
/bower_components/
.DS_Store

With the .gitignore created and installed Git you are ready to send your code to Github. If you haven’t created a local Git repository yet, follow the steps below:

Navigate to your project. I don’t know if you’re using Mac or Windows, but it’s simple in both cases. Open the terminal on your Mac or command prompt on Windows and navigate to the root folder of your project. You can use the command cd <caminho> in this case on both platforms.

Create a local repository. Still using command line, run git init to create the repository.

Commit to what you have. Execute git add . to add all the files in the folder to your pending commit changes. Anyway, run git commit -m "<mensagem qualquer>" effectively "commit" in the local repository.

Okay, local repository created, now for Github.

Create a Github repository. Clicking here and create a new repository. As you already have one .gitignore, create this repository without it.

Add your Github repository as remote. Use the command git remote add origin https://github.com/<seu_username>/<nome_repositorio>.git to define your remap remote.

Push local changes to the remote. Turn the command git push -u origin master.

Now just go up https://github.com/<seu_username>/<nome_repositorio> to see if everything is there as it should be.

2

Github has a repository with examples of .gitignore typical. One of them (link here) is the .gitignore for Node.js.

The function of the file .gitignore is exactly not sending to Git ephemeral files, files that are only needed in the build, and generally all files that are not part of the application code.

For other files there is the package.json which indicates the dependencies and which files and their versions to install with npm install.

The contents of this .gitignore for Node.js is:

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# ficheiros gerados pelo servidor, temporários
pids
*.pid
*.seed
*.pid.lock

# diretoria da ferramenta jscoverage/JSCover
lib-cov

# diretoria de ferramentas como o istanbul
coverage

# diretoria de respostas de testes de alguns programas
.nyc_output

# ficheiro temporário do Grunt
.grunt

# diretoria da ferramenta Bower
bower_components

# ficheiro de configuração de node-waf
.lock-wscript

# diretoria de ficheiros compilados (isto depende de que nome dás às pastas e se queres ou não ter ficheiros de release no Github)
build/Release

# Dependências
node_modules/
jspm_packages/

# diretoria da ferramenta typescript
typings/

# diretoria da npm opcional
.npm

# diretoria do eslint opcional
.eslintcache

# log/hitoria de REPL
.node_repl_history

# Resultado de comprimir com 'npm pack'
*.tgz

# Verificador de integridade do Yarn
.yarn-integrity

# variáveis do ambiente 
.env

Browser other questions tagged

You are not signed in. Login or sign up in order to post.