Month: May 2022

Git : Don’t commit node_modules except a file in a library

If you are using the node_modules in your Node.JS / Javascript / Typescript project you should exclude to commit all the libraries used by your application with this line in the .gitignore file:

.gitignore

node_modules/

But, you may need to modify a file in the /node_modules folder, excluded in the .gitignore

Force commit a file in a excluded folder in .gitignore

If you want to fix a file in a library that makes some problems in your application, you may want to modify the library directly in /node_modules (the case you are using the last version of the library, you can check on https://www.npmjs.com/ if you are using the last version in your package.json)

In my case, I modified node_modules/react-native-firebase/ios/RNFirebase/notifications/RNFirebaseNotifications.m a library that is not changed since 2 years and have a problem in my application. You can of course make a git issue on the official page but if you need it to work fast, you may want to commit it directly in your project and it is fixed.

After you made the change in the library, you can commit with git add -f …

In my case:

git add -f node_modules/react-native-firebase/ios/RNFirebase/notifications/RNFirebaseNotifications.m
You can see your file to be commit in your Git Desktop, and my node_modules folder is excluded in .gitignore

How to remove git token on git project after a failed git pull

After doing a git pull is it possible you have an error because your Git Token is not valid anymore, here is an exemple:

# git pull
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab-ci-token:YOURTOKEN@gitlab.com/YOURPROJECT.git/'

In order to do the git pull we want to use our credential with the LOGIN / PASSWORD that we use to access GitLab.

Solution 1 : Git pull one time with login (temporary)

# git pull https://gitlab.com/YOURPROJECT.git

Solution 2 : Change the origin URL to HTTPS (permanent)

# git remote set-url origin https://gitlab.com/YOURPROJECT.git
# git pull

It will ask your login and password for the git pull and will not use the git token anymore.