.gitignore is used for ignoring the files which are not expected to be commited to git. It locates in the root directory of the project. So this file should also be added and commited as other files or?
Yes, it's a good practice to commit it, to avoid people in your team to commits temporary files, builds, and other stuffs that aren't project specific.
But if you want to have a modified one locally with a private or testing configuration, you can but if you want to apply changes you have to add it with git add .gitignore.
Documentation: https://git-scm.com/docs/gitignore
Related
Quick question for anyone that is using AWS SAM to deploy their microservices in AWS.
Do you include your .aws-sam files into your repositories? Or do you gitignore this directory and sub directories?
No, you should not revision control the .aws-sam folder(s). Add them to .gitignore.
These folders contain intermediate and output files and will, for example, include Python packages, Node modules and other undesirables. None of these should be committed.
You don't need to include the .aws-sam directory in your repository.
The content of this directory are the artifacts outputted from your sam build command, and can always be recreated.
I initialized an empty git repository with git init and it's making only a .git folder. It's not making .gitignore itself. When I tried making a .gitignore file and then wrote \node_modules, it is not ignoring the node_modules folder. I am working with Linux OS on the NodeJs application and was pushing the code on GitHub.
It doesn't get generated automatically. You need to first commit it in the repo and use "node_module/" in your .gitignore file.
$ cat .gitignore
node_modules/
Try this as follows.
Do git init
Add .gitignore file
Add file path or folder path you
want to avoid
Commit as Git ignore file added or something.
Push to repository
After then if it's not working,
Clone it to another folder. It will work, sure.
I have a Node.js project and have imported a few Node modules. The git_status command shows the files that I changed in the project. I have also changed some files under the node_modules directory but those are not shown. The node_modules directory is shown as untracked.
Untracked files:
(use "git add <file>..." to include in what will be committed)
node_modules/
src/js/main-release-paths.json
I have changed only one file in node_modules:
node_modules/#oracle/grunt-oraclejet/node_modules/#oracle/oraclejet-tooling/lib/serve/connect.js
How can I track this file?
You shouldn't add the node_modules folder to git then it's managed bei the npm command. So remove that folder and use the npm install command.
When you have added something in that folder it's shown as changed, if you had first added some files. So i hop that folder is in your .gitignore file and ignored. You should check that.
Assuming you have git repo, Please check the .gitignore files inside your project. Entries in .gitignore will be ignored by Git and will not show up when you do git add.
Adding the file to track
This is most likely not a suitable approach (read below). However , if you really want to do it:
In order to track a file nested under node_modules, you should add the directory. All of its content will be staged in git
git add node_modules
Recommended approach
You probably don't want to track the contents of node_modules directory, because:
running npm install will wipe your changes
hundreds or thousand files are likely to end up present in that directory
tracking package.json and package-lock.json in git is sufficient, then populate node_modules using npm install command.
You are not supposed to modify files located in node_modules directory directly. Instead, fork the module in question, modify it, and:
either publish your own version in npm
or reference it as a git repository inside package.json (how-to)
Then, also add node_modules directory to the .gitignore file.
If the whole directory is untracked, git status will show only the directory. Because it's untracked, there is no meaningful difference to git between changed and unchanged files in there.
Other answers have already addressed that tracking node_modules is nota good idea. Of you want to track your changes to modules, consider cloning the module repo and including it as a git submodule.
It should be inside .gitignore file. A .gitignore file should be committed into your repository, in order to share the ignore rules with any other users that clone the repository.
I've done few searches before posting but none of them helped me.
I hold a git repository for my personal website, and I have a small problem when checking out one of its branches. There are 3 branches for different tools or frameworks : the former master branch, which acts as the current version of my website, & the Elm and Vue ones, that I'm working on at the same time. Each of these branches contains a package.jsons file and so a node_modules directory. My problem is : after checking out a branch, I have to 'yarn install' my packages to run the dev mode or build the app (with webpack), because of all the conflicted packages hosted in the same directory on different versions I guess.
It's a bit tiring to reinstall the required packages each time I checkout a branch. Moreover, I have then to commit the updated yarn.lock file.
So I am wondering if there is a way to create a specific node_modules folder or sub-folder, one for each branch, in order to have "scoped" directories. Or should I better separate this repo in 3 repos ?
I hope I am clear about this problem.
Thanks for reading !
You can commit node_modules so git will switch them on git checkout.
Or you can create separate worktrees. Checkout different branches in different worktrees and don't switch branches afterwards.
I have a fairly straightforward question it possible to include in the npm release the artifacts (files) but avoid to include them in the git repo (I guess with a combination of .npmignore and .gitignore)?
Yes - this is absolutely possible.
The way that npm handles this is during publish as follows:
Check if there is an .npmignore file present. If yes, exclude those files from the release. If not, fallback to step 2.
(optional) Check if there is a .gitignore file present. If yes, exclude those files from the release.
So, if you want to keep everything in your npm release, but avoid pushing them to your git repository, all you need to do is put those files in .gitignore and create an empty .npmignore file.
This way, npm won't try to fallback to .gitignore.