Developer Cheat Sheets
git config --global user.name "[name]"
git config --global user.name "[name]"
Description: Set your username globally for all repositories.
Scenario: First-time Git setup on a new machine.
Example:
git config --global user.name "Your Name"
git config --global user.email "[email]"
git config --global user.email "[email]"
Description: Set your email globally for all repositories.
Scenario: First-time Git setup on a new machine.
Example:
git config --global user.email "youremail@example.com"
git config --list
git config --list
Description: List all Git configurations.
Scenario: Verifying current Git settings.
Example:
git config --list
git init
git init
Description: Initialize a new Git repository.
Scenario: Starting a new project from scratch.
Example:
git init my-project
git clone [url]
git clone [url]
Description: Clone an existing repository.
Scenario: Getting a copy of an existing project.
Example:
git clone https://github.com/user/repo.git
git status
git status
Description: Show the working tree status.
Scenario: Checking what changes are ready to be committed.
Example:
git status
git add [file]
git add [file]
Description: Add file contents to the staging area.
Scenario: Preparing a specific file for commit.
Example:
git add index.html
git commit -m "[message]"
git commit -m "[message]"
Description: Record changes with a descriptive message.
Scenario: Saving your staged changes.
Example:
git commit -m "Add initial project structure"
git push origin [branch]
git push origin [branch]
Description: Upload local repository content to remote.
Scenario: Sharing your commits with the remote repository.
Example:
git push origin main
git pull origin [branch]
git pull origin [branch]
Description: Fetch and merge changes from remote.
Scenario: Updating your local branch with remote changes.
Example:
git pull origin main
git branch
git branch
Description: List all local branches.
Scenario: Seeing available branches.
Example:
git branch
git branch [branch-name]
git branch [branch-name]
Description: Create a new branch.
Scenario: Starting work on a new feature.
Example:
git branch feature-x
git checkout [branch]
git checkout [branch]
Description: Switch to an existing branch.
Scenario: Changing to a different branch.
Example:
git checkout develop
git checkout -b [branch]
git checkout -b [branch]
Description: Create and switch to a new branch.
Scenario: Creating and starting work on a new branch.
Example:
git checkout -b hotfix-123
git merge [branch]
git merge [branch]
Description: Merge the specified branch into current branch.
Scenario: Integrating changes from one branch into another.
Example:
git merge feature-x
docker images
docker images
Description: List all local images.
Scenario: Checking available Docker images on your system.
Example:
docker images
docker pull [image]
docker pull [image]
Description: Download an image from registry.
Scenario: Getting a new Docker image.
Example:
docker pull ubuntu:latest
docker build -t [name] .
docker build -t [name] .
Description: Build an image from Dockerfile.
Scenario: Creating a custom Docker image.
Example:
docker build -t myapp:v1 .
docker rmi [image]
docker rmi [image]
Description: Remove one or more images.
Scenario: Cleaning up unused images.
Example:
docker rmi myapp:v1
docker ps
docker ps
Description: List running containers.
Scenario: Checking active containers.
Example:
docker ps
docker run [image]
docker run [image]
Description: Create and start a new container.
Scenario: Running an application in a container.
Example:
docker run -d -p 8080:80 nginx
docker stop [container]
docker stop [container]
Description: Stop one or more running containers.
Scenario: Gracefully stopping a container.
Example:
docker stop my_container
docker exec -it [container] [command]
docker exec -it [container] [command]
Description: Run a command in a running container.
Scenario: Accessing a shell inside a container.
Example:
docker exec -it my_container bash
ls -la
ls -la
Description: List directory contents with details.
Scenario: Viewing files and directories with permissions.
Example:
ls -la /var/log
cd [directory]
cd [directory]
Description: Change current directory.
Scenario: Navigating the file system.
Example:
cd /var/log
mkdir [directory]
mkdir [directory]
Description: Create a new directory.
Scenario: Creating a new folder.
Example:
mkdir new_project
rm [file]
rm [file]
Description: Remove files.
Scenario: Deleting a file.
Example:
rm temp.txt
cp [source] [dest]
cp [source] [dest]
Description: Copy files or directories.
Scenario: Making a copy of a file.
Example:
cp file.txt backup/
mv [source] [dest]
mv [source] [dest]
Description: Move or rename files.
Scenario: Renaming or moving a file.
Example:
mv old.txt new.txt
cat [file]
cat [file]
Description: Display file content.
Scenario: Viewing the content of a file.
Example:
cat error.log
grep "[pattern]" [file]
grep "[pattern]" [file]
Description: Search for patterns in files.
Scenario: Finding specific text in a file.
Example:
grep -i "error" server.log
head [file]
head [file]
Description: Show first lines of a file.
Scenario: Viewing the beginning of a large file.
Example:
head -n 20 access.log
tail [file]
tail [file]
Description: Show last lines of a file.
Scenario: Monitoring log files in real-time.
Example:
tail -f app.log
array.map(callback)
array.map(callback)
Description: Transform each element in an array.
Scenario: Converting an array of numbers to their doubles.
Example:
const doubled = numbers.map(n => n * 2)
array.filter(callback)
array.filter(callback)
Description: Create a new array with filtered elements.
Scenario: Getting only even numbers from an array.
Example:
const evens = numbers.filter(n => n % 2 === 0)
array.reduce(callback, initial)
array.reduce(callback, initial)
Description: Reduce array to a single value.
Scenario: Calculating the sum of all numbers.
Example:
const sum = numbers.reduce((acc, n) => acc + n, 0)
array.find(callback)
array.find(callback)
Description: Find the first element that matches condition.
Scenario: Finding a specific user by ID.
Example:
const found = users.find(user => user.id === 1)
const { prop } = object
const { prop } = object
Description: Destructure properties from objects.
Scenario: Extracting specific properties from an object.
Example:
const { name, age } = user
const [first, ...rest] = array
const [first, ...rest] = array
Description: Destructure arrays with spread operator.
Scenario: Getting the first element and the rest separately.
Example:
const "color: #fbbf24;">[head, ...tail] = "color: #fbbf24;">[1, 2, 3, 4]
async function name() {}
async function name() {}
Description: Define an asynchronous function.
Scenario: Making asynchronous API calls.
Example:
async function fetchData() { return await api.get('/data') }
const result = await promise
const result = await promise
Description: Wait for a promise to resolve.
Scenario: Waiting for an API response.
Example:
const data = await fetch('/api/users')