This week of Things I learned, I would like to write about some git commands. These commands are parts of my daily usage. I would end up googling them every time they needed and go through a lot a links until land on the correct result. To save time I have gathered them at one place.
- Remove Git branch locally and remotely
- Configure Git username and email
- Look for dependency in a project or npm search dependency tree
Remove Git branch locally and remotely
The excerpt for this Stack overflow link is as follows
# to remove local branch git branch -d branch_name # to remove remote branch git push <remote_name> --delete <branch_name> # git push origin --delete updateTong9
Git command to configure user name and email
When you create a new git project and push it to github, the global user name and email is picked up. If you haven’t configure them globally you can test them by running following command in the terminal.
# to list global configuration git config --global --list # to list git configuration of current project git config --list
If no name or email is configure than we have a dummy gravatar icon on git hosting platforms i-e github, gitlab. When you set you email either globally or locally ( repsitory specific) the avatar is picked from gravatar.com.
There is one more use case to setup local git configurations. For example at work I have different global user and email. When I work on personal toy project and push commits, the are pushed with my office identity i-e global configs. May be I want the commits to be tracked by different user. In that case the only solution to setup repository specific configuration using following git commands. Excerpt taken from atlassian article.
# globally git config --global user.name "FIRST_NAME LAST_NAME" git config --global user.email "[email protected]" # repository specific git config user.name "FIRST_NAME LAST_NAME" git config user.name "FIRST_NAME LAST_NAME"
NPM Search dependency tree
The urgency to search through your
node_modules for certain npm project is when github alerts us about potential security vulnerability
In our case I had to search for minimist dependency. I haven’t used it directly. May be one of my dependency have used or may be dep of dep have used. One can imagine the nested hierarchy here. So npm command to help in such condition is
npm ls npm ls minimist
For me I got following result.
Now updating firebase might fix it. (I think github can also auto fix by creating a pull request).