├── LICENSE ├── README.md ├── docker.md ├── general.md ├── git.md └── npm.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mohamed Shadab 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Developer Cheatsheet 2 | 3 | A collection of handy commands I've found during development. 4 | 5 | ## Table of Contents 6 | 7 | 1. [General commands](./general.md) 8 | 2. [Git commands](./git.md) 9 | 3. [Docker commands](./docker.md) 10 | 4. [NPM commands](./npm.md) 11 | 12 | ## License 13 | 14 | This project is licensed under the MIT License - Copyright (c) 2020 Mohamed Shadab 15 | -------------------------------------------------------------------------------- /docker.md: -------------------------------------------------------------------------------- 1 | # Docker Commands 2 | 3 | ### 1. Create an image: 4 | 5 | ```bash 6 | # Inside the folder with Dockerfile 7 | docker build -t . 8 | ``` 9 | 10 | ### 2. Run an image: 11 | 12 | - Regular: 13 | 14 | ```bash 15 | docker run 16 | ``` 17 | 18 | - Binding a port at run time: 19 | 20 | ```bash 21 | docker run -p : 22 | ``` 23 | 24 | - Setting a name for the container at run time: 25 | 26 | ```bash 27 | docker run --name 28 | ``` 29 | 30 | - Running a container in the background (detached): 31 | 32 | ```bash 33 | docker run -d 34 | ``` 35 | 36 | ### 3. List your images: 37 | 38 | ```bash 39 | docker image ls 40 | ``` 41 | 42 | ### 4. Delete a specific image: 43 | 44 | ```bash 45 | docker image rm [image name] 46 | ``` 47 | 48 | ### 5. Delete all existing images: 49 | 50 | ```bash 51 | docker image rm $(docker images -a -q) 52 | ``` 53 | 54 | ### 6. List all existing containers (running and not running): 55 | 56 | ```bash 57 | docker ps -a 58 | ``` 59 | 60 | ### 7. Stop a specific container: 61 | 62 | ```bash 63 | docker stop [container name] 64 | ``` 65 | 66 | ### 8. Stop all running containers: 67 | 68 | ```bash 69 | docker stop $(docker ps -a -q) 70 | ``` 71 | 72 | ### 9. Delete a specific container (only if stopped): 73 | 74 | ```bash 75 | docker rm [container name] 76 | ``` 77 | 78 | ### 10. Delete all containers (only if stopped): 79 | 80 | ```bash 81 | docker rm $(docker ps -a -q) 82 | ``` 83 | 84 | ### 11. Display logs of a container: 85 | 86 | ```bash 87 | docker logs [container name] 88 | ``` 89 | 90 | ### 12. Build using docker compose: 91 | 92 | ```bash 93 | # In the repository with docker-compose.yml 94 | docker-compose build 95 | ``` 96 | 97 | ### 13. Starting containers using docker compose: 98 | 99 | - Regular: 100 | 101 | ```bash 102 | # In the repository with docker-compose.yml 103 | docker-compose up 104 | ``` 105 | 106 | - Background (Detached mode): 107 | 108 | ```bash 109 | # In the repository with docker-compose.yml 110 | docker-compose up -d 111 | ``` 112 | 113 | ### 14. Deleting all untagged(dangling) images: 114 | 115 | ```bash 116 | docker rmi $(docker images -f “dangling=true” -q) 117 | ``` 118 | 119 | ### 15. Executing a command in a running container: 120 | 121 | ```bash 122 | docker exec 123 | ``` 124 | -------------------------------------------------------------------------------- /general.md: -------------------------------------------------------------------------------- 1 | # General Commands 2 | 3 | General commands for linux/shell/bash etc. 4 | 5 | ### 1. To move files (and folders) (can be used to rename files/folders): 6 | 7 | ```bash 8 | mv 9 | ``` 10 | 11 | ### 2. Delete a folder with files in it: 12 | 13 | ```bash 14 | rm -rf 15 | ``` 16 | 17 | ### 3. To list files and folders inside present working directory: 18 | 19 | - Basic use: 20 | 21 | ```bash 22 | ls 23 | ``` 24 | 25 | - List hidden folders too: 26 | 27 | ```bash 28 | ls -a 29 | ``` 30 | 31 | ### 4. To get the path of the present working directory: 32 | 33 | ```bash 34 | pwd 35 | ``` 36 | 37 | ### 5. Compress/Extract a folder using tar: 38 | 39 | - Compress: 40 | 41 | ```bash 42 | tar -zcvf .gz 43 | ``` 44 | 45 | * Extract: 46 | 47 | ```bash 48 | tar -xf .gz 49 | ``` 50 | 51 | ### 6. Send a file using SCP to a remote server: 52 | 53 | ```bash 54 | scp @:/remote/folder/ 55 | ``` 56 | -------------------------------------------------------------------------------- /git.md: -------------------------------------------------------------------------------- 1 | # Git Commands 2 | 3 | ## Stash superpowers 4 | 5 | > Great tutorial: https://www.atlassian.com/git/tutorials/saving-changes/git-stash 6 | 7 | Knowing how to leverage `git stash` is a superpower and the following commands will allow you to do just that: 8 | 9 | - Basic use (will store current changes to the stash): 10 | 11 | ```bash 12 | git stash 13 | ``` 14 | 15 | - Save untracked files by: 16 | 17 | ``` 18 | git stash -u 19 | ``` 20 | 21 | - View(list) your stash: 22 | 23 | ```bash 24 | git stash list 25 | ``` 26 | 27 | - Store a stash with a message: 28 | 29 | ```bash 30 | git stash save "fire" 31 | ``` 32 | 33 | - Pop a stash(will pop the recent most stash): 34 | 35 | ```bash 36 | git stash pop 37 | ``` 38 | 39 | - Pop a specific stash: 40 | 41 | ```bash 42 | git stash pop 43 | ``` 44 | 45 | - Apply a stash without removing it(will apply the recent most stash): 46 | 47 | ```bash 48 | git stash apply 49 | ``` 50 | 51 | - Apply a specific stash without removing it: 52 | 53 | ```bash 54 | git stash apply 55 | ``` 56 | 57 | ## Regular 58 | 59 | ### 1. To stop tracking a file (which is present in .gitignore): 60 | 61 | ```bash 62 | git rm --cached 63 | ``` 64 | 65 | ### 2. Keeping a fork upto date: 66 | 67 | - Add remote from original repository in your forked repository: 68 | 69 | ```bash 70 | cd into/cloned/fork-repo 71 | # remote name can be anything you want 72 | git remote add git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git 73 | git fetch 74 | ``` 75 | 76 | - Updating your fork from original repo to keep up with their changes: 77 | 78 | ```bash 79 | # for branch master (you can change this for any branch) 80 | git pull master 81 | ``` 82 | 83 | - To update the remote fork on GitHub (or any other git hosting site): 84 | 85 | ```bash 86 | # this assumes that the remote forks name is origin (which is usually the case) 87 | # branch name can be changed up to your liking 88 | git push origin master 89 | ``` 90 | 91 | ### 3. Amending a staged changed to a previous commit or updating the commit message: 92 | 93 | - Regular (will open selected editor for editing commit message): 94 | 95 | ```bash 96 | git commit --amend 97 | ``` 98 | 99 | - Editing the commit message directly: 100 | 101 | ```bash 102 | git commit --amend -m "" 103 | ``` 104 | 105 | - Without editing commit message: 106 | 107 | ```bash 108 | git commit --amend --no-edit 109 | ``` 110 | 111 | ### 4. Deleting tags (locally and remotely): 112 | 113 | - Delete local tag: 114 | 115 | ```bash 116 | git tag -d 117 | ``` 118 | 119 | - Delete remote tag (for eg. on GitHub) 120 | 121 | ```bash 122 | git push --delete origin 123 | ``` 124 | 125 | ### 5. Resetting a repo to a certain commit along with a remote(this will delete the changes made): 126 | 127 | ```bash 128 | git reset --hard 129 | git push -f master 130 | ``` 131 | 132 | ### 6. Viewing the current code diff: 133 | 134 | ```bash 135 | git diff 136 | ``` 137 | 138 | ### 7. Reverting changes done in a folder: 139 | 140 | - If you have not yet indexed (git add) your changes: 141 | 142 | ```bash 143 | git checkout -- path/to/folder 144 | ``` 145 | 146 | - If changes are indexed then you need to reset that first: 147 | 148 | ```bash 149 | git reset -- path/to/folder 150 | git checkout -- path/to/folder 151 | ``` 152 | 153 | ### 8. Updating the local list of remote branches: 154 | 155 | ```bash 156 | git remote update origin --prune 157 | ``` 158 | 159 | ### 9. Renaming a local branch: 160 | 161 | ```bash 162 | git branch -m 163 | ``` 164 | 165 | ### 10. Undoing your last commit: 166 | 167 | ```bash 168 | git reset HEAD~ 169 | ``` 170 | -------------------------------------------------------------------------------- /npm.md: -------------------------------------------------------------------------------- 1 | # NPM Commands 2 | 3 | ### 1. To list the packages installed: 4 | 5 | - Global packages 6 | 7 | ```bash 8 | npm ls -g --depth 0 9 | ``` 10 | 11 | - Local packages 12 | 13 | ```bash 14 | npm ls 15 | ``` 16 | 17 | - Specific local package 18 | 19 | ```bash 20 | npm ls 21 | ``` 22 | 23 | ### 2. To visit the link in the 'repository' field of the package.json: 24 | 25 | ```bash 26 | npm repo 27 | ``` 28 | 29 | ### 3. To initialize a repo: 30 | 31 | - Basic use: 32 | 33 | ```bash 34 | npm init 35 | ``` 36 | 37 | - With all defaults: 38 | 39 | ```bash 40 | npm init --y 41 | ``` 42 | 43 | ### 4. To add a package from a GitHub repository: 44 | 45 | ```bash 46 | npm install 47 | ``` 48 | --------------------------------------------------------------------------------