Skip to main content

4 posts tagged with "Playwright"

End-to-end testing with Playwright for web applications.

View All Tags

Supercharging Playwright with AI โ€“ Intelligent Test Case Generation Using GPT Models

ยท 4 min read
Deepak Kamboj
Senior Software Engineer

Modern applications are evolving fast, and so should our testing. Manual test case writing can't keep pace with complex UIs, rapid development, and ever-increasing test coverage demands. This is where AI-powered test generation shines.

In this article, you'll discover how to leverage GPT models to generate Playwright tests automatically from user stories, mockups, and API specsโ€”cutting test creation time by up to 80% and boosting consistency.


๐Ÿš€ The AI Testing Revolution โ€“ Why Now?โ€‹

Web applications today have:

  • Dynamic UIs
  • Complex workflows
  • Rapid iteration cycles

Manual testing falls short due to:

  • โณ Time-consuming scripting
  • ๐ŸŽฏ Inconsistent test quality
  • ๐Ÿ›  High maintenance overhead
  • ๐Ÿ“‰ Skill gaps in Playwright expertise

IMPORTANT: AI-generated tests solve these issues by converting high-level specifications into consistent, executable scriptsโ€”within minutes.


๐Ÿ” Core Use Casesโ€‹

1. ๐Ÿงพ User Story โ†’ Test Scriptโ€‹

User Story: โ€œAs a customer, I want to add items to my shopping cart, modify quantities, and checkout.โ€

An LLM can auto-generate Playwright tests for:

  • Item addition/removal
  • Quantity updates
  • Cart persistence
  • Checkout validation

2. ๐Ÿงฉ UI Mockups โ†’ UI Testsโ€‹

From screenshots or Figma mockups, AI identifies UI components and generates:

  • Field validation tests
  • Button click paths
  • Navigation workflows

3. ๐Ÿ“ก API Docs โ†’ Integration Testsโ€‹

Given OpenAPI specs or Swagger files, AI generates:

  • API response validators
  • Auth flow tests
  • Data transformation checks

4. ๐Ÿ” Regression Suite Generationโ€‹

Scan your codebase and let AI generate:

  • Tests for business-critical paths
  • Version-aware regression scenarios
  • Cross-browser validations

โœ๏ธ Prompt Engineering: The Secret Sauceโ€‹

High-quality output requires high-quality prompts.

TIP: Craft prompts like you're onboarding a new teammate. Be specific, structured, and clear.

๐Ÿง  Tips for Better Promptsโ€‹

  1. Context-Rich: Include business logic, user persona, architecture info.
  2. Structured Templates: Use consistent input formats.
  3. Code Specs: Tell the AI about your conventions, selectors, assertions.

๐Ÿ› ๏ธ How AI Builds Playwright Testsโ€‹

The test generation pipeline includes:

  • Requirement parsing
  • Scenario/edge case detection
  • Selector/locator inference
  • Assertion strategy
  • Setup/teardown

TIP: AI-generated tests often contain proper waits, good selectors, and meaningful error handling out of the box.


๐Ÿ”ฌ Examples by Domainโ€‹

๐Ÿ›’ E-commerce Cartโ€‹

  • Add/remove items
  • Update quantity
  • Validate prices
  • Empty cart flows

๐Ÿ“‹ Form Validationโ€‹

  • Required field checks
  • Format enforcement
  • Success + error paths
  • Accessibility & UX feedback

๐Ÿ”„ API Integrationโ€‹

  • GET/POST/PUT/DELETE tests
  • 401/403/500 handlers
  • JSON schema validation
  • Token expiration

โš–๏ธ AI vs. Manual Testsโ€‹

MetricAI-GeneratedManual
Creation Timeโšก ~85% faster๐Ÿข Slower
Initial Coverage๐Ÿ“ˆ ~40% higher๐Ÿ‘จโ€๐Ÿ’ป Depends on tester
Bug Detection๐Ÿž ~15% higher๐Ÿง  Domain-aware
Maintenance๐Ÿงน +20% overhead๐Ÿ”ง Controlled
False Positives๐Ÿ”„ ~25% higherโœ… Lower
Business Logic๐Ÿง  ~10% less accurate๐ŸŽฏ High fidelity

IMPORTANT: Use AI for breadth, and humans for depth. Combine both for maximum coverage.


๐Ÿง  Advanced Prompt Engineeringโ€‹

๐Ÿงช Multi-Shot Promptingโ€‹

Provide several examples for the AI to follow.

๐Ÿงต Chain-of-Thought Promptingโ€‹

Ask AI to reason before generating.

๐Ÿ” Iterative Refinementโ€‹

Start, review, improve. Repeat.

๐ŸŽญ Role-Based Promptingโ€‹

โ€œAct like a senior QAโ€ gets better results than generic prompts.


๐Ÿงฉ Integrating AI into Your CI/CD Workflowโ€‹

Phase 1: Foundationโ€‹

  • Define test structure
  • Create reusable prompt templates
  • Set up review pipelines

Phase 2: Pilotโ€‹

  • Begin with UI flows, login, cart, or forms
  • Involve human reviewers

Phase 3: Scaleโ€‹

  • Add coverage for APIs, edge cases
  • Train team on prompt best practices

๐Ÿ›ก๏ธ Maintaining AI-Generated Testsโ€‹

Use tagging to distinguish AI-generated files.

Review regularly for:

  • Fragile selectors
  • Obsolete flows
  • Over-tested paths

TIP: Use GitHub Actions to auto-regenerate stale tests weekly.


๐Ÿ“ˆ KPIs to Trackโ€‹

KPIPurpose
Test Creation TimeVelocity
Bug Catch RateQuality
Maintenance TimeOverhead
False PositivesTrust
Coverage GainedROI

  • ๐Ÿ–ผ๏ธ Visual test generation from screenshots
  • ๐Ÿ—ฃ๏ธ Natural language test execution (e.g., โ€œTest checkout flowโ€)
  • ๐Ÿ” Adaptive test regeneration on UI changes
  • ๐Ÿ” Predictive test flakiness detection

โœ… Final Thoughtsโ€‹

AI doesnโ€™t replace your QA teamโ€”it supercharges them.

By combining:

  • GPT-based prompt generation
  • Human review and refinement
  • CI/CD integration

You can reduce time-to-test by weeks while increasing test quality.

CTA: Try our GitHub starter kit and let AI handle the boring test boilerplate while your team focuses on real innovation.

The future of testing isnโ€™t just fasterโ€”itโ€™s intelligent.

Step-by-Step Guide to Creating a Website with Next.js, React, and Tailwind CSS

ยท 8 min read
Deepak Kamboj
Senior Software Engineer

This guide will walk you through the process of creating a web application using Next.js, React, and Tailwind CSS. The application will include pages for the homepage, login, register, and dashboard, and will implement a persistent Redux store with types, actions, reducers, and sagas. Additionally, it will support both database and social login, feature light and dark themes, and include header and footer components. We will also set up private and public routes and provide commands for building, starting, and deploying the application on Vercel.

Prerequisitesโ€‹

  • Node.js installed on your machine
  • Basic knowledge of JavaScript and React
  • Familiarity with Redux and Next.js

1. Setting Up the Next.js Projectโ€‹

  1. Create a new Next.js application:
npx create-next-app my-next-app
cd my-next-app

Use below command to create a new Next.js application with TypeScript:

npx create-next-app my-next-app --typescript
cd my-next-app
  1. Install Tailwind CSS: Follow the official Tailwind CSS installation guide for Next.js:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
  1. Configure Tailwind CSS: Update tailwind.config.js:
module.exports = {
content: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
plugins: [],
};
  1. Add Tailwind to your CSS: In styles/globals.css, add the following:
@tailwind base;
@tailwind components;
@tailwind utilities;

2. Setting Up Reduxโ€‹

  1. Install Redux and related libraries:
npm install redux react-redux redux-saga
  1. Create Redux Store: Create a folder named store and add the following files:

    • store/index.js:
    import { createStore, applyMiddleware } from 'redux';
    import createSagaMiddleware from 'redux-saga';
    import rootReducer from './reducers';
    import rootSaga from './sagas';

    const sagaMiddleware = createSagaMiddleware();
    const store = createStore(rootReducer, applyMiddleware(sagaMiddleware));

    -sagaMiddleware.run(rootSaga);

    export default store;
    • store/reducers/index.js:
    import { combineReducers } from 'redux';
    import authReducer from './authReducer';

    const rootReducer = combineReducers({
    auth: authReducer,
    });

    export default rootReducer;
    • store/reducers/authReducer.js:
    const initialState = {
    user: null,
    loading: false,
    error: null,
    };

    const authReducer = (state = initialState, action) => {
    switch (action.type) {
    case 'LOGIN_REQUEST':
    return { ...state, loading: true };
    case 'LOGIN_SUCCESS':
    return { ...state, loading: false, user: action.payload };
    case 'LOGIN_FAILURE':
    return { ...state, loading: false, error: action.payload };
    default:
    return state;
    }
    };

    export default authReducer;
    • store/sagas/index.js:
    import { all } from 'redux-saga/effects';
    import authSaga from './authSaga';

    export default function\* rootSaga() {
    yield all([
    authSaga(),
    ]);
    }
    • store/sagas/authSaga.js:
    import { call, put, takeEvery } from 'redux-saga/effects';
    import { loginService } from '../services/authService';

    function\* login(action) {
    try {
    const user = yield call(loginService, action.payload);
    yield put({ type: 'LOGIN_SUCCESS', payload: user });
    } catch (error) {
    yield put({ type: 'LOGIN_FAILURE', payload: error.message });
    }
    }

    export default function\* authSaga() {
    yield takeEvery('LOGIN_REQUEST', login);
    }
  2. Create Services for MySQL: Create a folder named services and add the following file:

    • services/authService.js:
import axios from 'axios';

export const loginService = async (credentials) => {
const response = await axios.post('/api/login', credentials);
return response.data;
};

3. Creating Pagesโ€‹

  1. Homepage (pages/index.js):
import Head from 'next/head';

const Home = () => {
return (
<div>
<Head>
<title>Home</title>
</Head>
<h1 className="text-4xl">Welcome to My Next.js App</h1>
</div>
);
};

export default Home;
  1. Login Page (pages/login.js):
import { useDispatch } from 'react-redux';

const Login = () => {
const dispatch = useDispatch();

const handleLogin = (e) => {
e.preventDefault();
const credentials = {
username: e.target.username.value,
password: e.target.password.value,
};
dispatch({ type: 'LOGIN_REQUEST', payload: credentials });
};

return (
<form onSubmit={handleLogin}>
<input name="username" type="text" placeholder="Username" required />
<input name="password" type="password" placeholder="Password" required />
<button type="submit">Login</button>
</form>
);
};

export default Login;
  1. Register Page (pages/register.js):
const Register = () => {
return (
<form>
<input name="username" type="text" placeholder="Username" required />
<input name="email" type="email" placeholder="Email" required />
<input name="password" type="password" placeholder="Password" required />
<button type="submit">Register</button>
</form>
);
};

export default Register;
  1. Dashboard Page (pages/dashboard.js):
const Dashboard = () => {
return (
<div>
<h1>Dashboard</h1>
</div>
);
};

export default Dashboard;

4. Implementing Themesโ€‹

  1. Create a Theme Context: Create a folder named context and add the following file:

    • context/ThemeContext.js:
import { createContext, useContext, useState } from 'react';

const ThemeContext = createContext();

export const ThemeProvider = ({ children }) => {
const [theme, setTheme] = useState('light');

const toggleTheme = () => {
setTheme((prev) => (prev === 'light' ? 'dark' : 'light'));
};

return <ThemeContext.Provider value={{ theme, toggleTheme }}>{children}</ThemeContext.Provider>;
};

export const useTheme = () => useContext(ThemeContext);
  1. Wrap the Application with ThemeProvider: In pages/\_app.js, wrap your application with the ThemeProvider:
import { ThemeProvider } from '../context/ThemeContext';

function MyApp({ Component, pageProps }) {
return (
<ThemeProvider>
<Component {...pageProps} />
</ThemeProvider>
);
}

export default MyApp;
  1. Header Component (components/Header.js):
import Link from 'next/link';
import { useTheme } from '../context/ThemeContext';

const Header = () => {
const { toggleTheme } = useTheme();

return (
<header>
<nav>
<Link href="/">Home</Link>
<Link href="/login">Login</Link>
<Link href="/register">Register</Link>
<Link href="/dashboard">Dashboard</Link>
<button onClick={toggleTheme}>Toggle Theme</button>
</nav>
</header>
);
};

export default Header;
  1. Footer Component (components/Footer.js):
const Footer = () => {
return (
<footer>
<p>ยฉ 2024 My Next.js App</p>
</footer>
);
};

export default Footer;
  1. Include Header and Footer in Pages: Update your pages to include the Header and Footer components:
import Header from '../components/Header';
import Footer from '../components/Footer';

const Home = () => {
return (
<div>
<Header />
<h1>Welcome to My Next.js App</h1>
<Footer />
</div>
);
};

export default Home;

6. Implementing Private and Public Routesโ€‹

  1. Create a Higher-Order Component for Route Protection: Create a folder named hocs and add the following file:

    • hocs/withAuth.js:
import { useSelector } from 'react-redux';
import { useRouter } from 'next/router';
import React from 'react';

const withAuth = (WrappedComponent) => {
const AuthenticatedComponent = (props) => {
const router = useRouter();
const user = useSelector((state) => state.auth.user);

// Redirect to login if user is not authenticated
React.useEffect(() => {
if (!user) {
router.push('/login');
}
}, [user, router]);

return user ? <WrappedComponent {...props} /> : null;
};

return AuthenticatedComponent;
};

export default withAuth;
  1. Protect the Dashboard Page: Update your Dashboard page to use the withAuth HOC:

    • pages/dashboard.js:
    import withAuth from '../hocs/withAuth';

    const Dashboard = () => {
    return (
    <div>
    <h1>Dashboard</h1>
    </div>
    );
    };

    export default withAuth(Dashboard);
  2. Public Route Example: For pages like login and register, you can create a similar HOC to prevent logged-in users from accessing these pages:

    • hocs/withPublic.js:
    import { useSelector } from 'react-redux';
    import { useRouter } from 'next/router';
    import React from 'react';

    const withPublic = (WrappedComponent) => {
    const PublicComponent = (props) => {
    const router = useRouter();
    const user = useSelector((state) => state.auth.user);

    // Redirect to dashboard if user is already authenticated
    React.useEffect(() => {
    if (user) {
    router.push('/dashboard');
    }
    }, [user, router]);

    return <WrappedComponent {...props} />;
    };

    return PublicComponent;
    };

    export default withPublic;
  3. Update Login and Register Pages: Use withPublic on the login and register pages:

    • pages/login.js:
    import { useDispatch } from 'react-redux';
    import withPublic from '../hocs/withPublic';

    const Login = () => {
    const dispatch = useDispatch();

    const handleLogin = (e) => {
    e.preventDefault();
    const credentials = {
    username: e.target.username.value,
    password: e.target.password.value,
    };
    dispatch({ type: 'LOGIN_REQUEST', payload: credentials });
    };

    return (
    <form onSubmit={handleLogin}>
    <input name="username" type="text" placeholder="Username" required />
    <input name="password" type="password" placeholder="Password" required />
    <button type="submit">Login</button>
    </form>
    );
    };

    export default withPublic(Login);
    • pages/register.js:
    import withPublic from '../hocs/withPublic';

    const Register = () => {
    return (
    <form>
    <input name="username" type="text" placeholder="Username" required />
    <input name="email" type="email" placeholder="Email" required />
    <input name="password" type="password" placeholder="Password" required />
    <button type="submit">Register</button>
    </form>
    );
    };

    export default withPublic(Register);

7. Implementing Light and Dark Themesโ€‹

  1. Add Theme Classes: Update your ThemeProvider to apply dark and light theme classes to the app.

    • context/ThemeContext.js:
    const ThemeProvider = ({ children }) => {
    const [theme, setTheme] = useState('light');

    const toggleTheme = () => {
    setTheme((prev) => (prev === 'light' ? 'dark' : 'light'));
    };

    return (
    <div className={theme}>
    <ThemeContext.Provider value={{ theme, toggleTheme }}>{children}</ThemeContext.Provider>
    </div>
    );
    };
  2. Add Tailwind CSS for Themes: In your styles/globals.css, include styles for dark mode:

/* Dark mode styles */ 
.dark {
@apply bg-gray-900 text-white;
}
  1. Update Components: Ensure your components utilize the theme classes accordingly.

8. Commands for Build, Start, and Deploy on Vercelโ€‹

  1. Build Command: Add the following scripts to your package.json file:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"deploy": "vercel --prod"
}
  1. Deploying to Vercel:

    • First, install the Vercel CLI globally if you haven't already:
    npm install -g vercel
    • To deploy your application, run the following command in your project directory:
    vercel
    • Follow the prompts to link your project to a Vercel account.

    To deploy to production, use:

    npm run deploy

Conclusionโ€‹

You have now set up a Next.js application using React and Tailwind CSS with a complete functionality including user authentication, light and dark themes, and routing. You can further extend this application by adding more features as needed. Happy coding!

Additional Resourcesโ€‹

This guide serves as a comprehensive starting point. Feel free to customize and enhance your application as you see fit!

Comprehensive Guide to GitHub Copilot Commands

ยท 5 min read
Deepak Kamboj
Senior Software Engineer

GitHub Copilot is an AI-powered coding assistant that helps developers by providing code suggestions and automating repetitive coding tasks. This document outlines the key commands, features, and usage scenarios for GitHub Copilot.

Activation and Basic Commandsโ€‹

TaskCommand / ShortcutDescription
Enable GitHub Copilot in VS CodeCommand Palette: GitHub Copilot: EnableActivates GitHub Copilot in your VS Code editor.
Disable GitHub Copilot in VS CodeCommand Palette: GitHub Copilot: DisableDeactivates GitHub Copilot in your VS Code editor.
Accept Copilot suggestionTabInserts the selected Copilot suggestion into your code.
Dismiss Copilot suggestionEscDismisses the current suggestion.
View additional suggestionsAlt + ] / Alt + [Cycles through multiple suggestions.
Trigger a suggestion manuallyCtrl + Enter (Windows/Linux) or Cmd + Enter (Mac)Manually triggers Copilot to generate code suggestions.

Comment-Based Commandsโ€‹

GitHub Copilot can be directed using comments to produce specific code snippets, examples, or logic.

TaskCommand / CommentDescription
Generate a function// Function to <description>Provides a function based on the description in the comment.
Complete a class definition// Class for <description>Suggests a full class definition with methods and properties based on the comment.
Explain a piece of code// Explain this code:Produces a comment that explains the following code snippet.
Write a test function// Test for <function_name>Generates a test function for the specified function.
Create a documentation comment/**Starts a block comment, and Copilot will auto-suggest a detailed documentation comment.

Code Completion Commandsโ€‹

GitHub Copilot can automatically complete your code based on the context provided by your current file.

TaskCommand / ShortcutDescription
Auto-complete a line of codeStart typingCopilot suggests a completion for the current line of code.
Complete multiple lines of codeStart typing or add a trigger wordCopilot suggests completions for multiple lines of code at once.
Continue an unfinished functionBegin the function bodyCopilot suggests how to complete the function based on its name and initial comments.

Advanced Suggestionsโ€‹

GitHub Copilot can be used for more advanced coding scenarios, including refactoring, generating boilerplate code, and handling specific languages or frameworks.

TaskCommand / ShortcutDescription
Generate boilerplate code// Boilerplate for <framework/task>Creates boilerplate code for a specific framework or task, such as setting up a new API endpoint.
Suggest refactoring// Refactor this functionSuggests a refactor for the code based on common best practices.
Optimize code for performance// Optimize this code for <goal>Provides performance optimization suggestions based on the specified goal (e.g., speed, memory).
Suggest code in specific language// Write in <language>Instructs Copilot to generate code in a specific programming language.

Testing and Debuggingโ€‹

GitHub Copilot can assist with writing tests, debugging code, and providing potential fixes.

TaskCommand / CommentDescription
Generate unit tests// Write unit tests for <function/class>Automatically writes unit tests for the specified function or class.
Provide test cases// Provide test cases for <scenario>Suggests multiple test cases for a given scenario or function.
Suggest bug fixes// Fix this bug:Suggests potential bug fixes or improvements based on the existing code.
Debug a function// Debug <function_name>Offers debugging tips or inserts debugging code such as logging statements.

Copilot in Pair Programmingโ€‹

When paired with another developer or using pair programming practices, GitHub Copilot can still assist without taking over the coding session.

TaskCommand / CommentDescription
Provide suggestions without auto-insertCommand Palette: GitHub Copilot: Toggle Suggestions InlinePrevents Copilot from auto-inserting code, allowing manual insertion only when approved.
Collaborate on suggestionsCommand Palette: GitHub Copilot: Show Side-by-Side SuggestionsDisplays suggestions in a side panel for collaborative review and discussion.
Review generated code// Review this code:Requests Copilot to generate comments or reviews for the current code snippet.

Language-Specific Commandsโ€‹

GitHub Copilot is language-agnostic, but you can tailor its suggestions to specific languages by using commands or comments relevant to the language's syntax or idioms.

LanguageCommand / CommentDescription
Python# Function to <task>Generates Pythonic code with appropriate idioms and best practices.
JavaScript/TypeScript// Create a <task>Suggests JavaScript or TypeScript code depending on the context and file type.
SQL-- Query to <task>Generates SQL queries or scripts based on the provided description.
HTML/CSS<!-- HTML code to <task> -->Produces HTML or CSS code snippets for web development tasks.

Settings and Customizationโ€‹

Users can customize how GitHub Copilot behaves within their IDE or editor.

TaskCommand / ShortcutDescription
Open Copilot settingsCommand Palette: GitHub Copilot: SettingsOpens the settings panel for configuring GitHub Copilot.
Enable/Disable inline suggestionsCommand Palette: GitHub Copilot: Toggle Inline SuggestionsControls whether Copilot provides inline code suggestions or not.
Adjust Copilot's behaviorCommand Palette: GitHub Copilot: ConfigureAccesses advanced configuration options for GitHub Copilot.
Set up keybindingsKeyboard Shortcuts PanelAssign custom keybindings for Copilot commands in your editor.

Miscellaneousโ€‹

Other useful commands and features that enhance your coding experience with GitHub Copilot.

TaskCommand / ShortcutDescription
View GitHub Copilot documentationCommand Palette: GitHub Copilot: Open DocsOpens the official GitHub Copilot documentation.
Give feedback on a suggestionAlt + \Opens a feedback form for the current suggestion, allowing you to rate its usefulness.
Enable Copilot LabsCommand Palette: GitHub Copilot Labs: EnableActivates experimental features and commands in GitHub Copilot Labs.
View Copilot's suggestions logCommand Palette: GitHub Copilot: View LogDisplays a log of all suggestions made during the current session.

This guide should help you make the most of GitHub Copilot's capabilities, enhancing your productivity and coding experience.

Comprehensive Guide to Git Commands

ยท 7 min read
Deepak Kamboj
Senior Software Engineer

This document provides a detailed overview of commonly used Git commands, organized by category.

Git Configurationโ€‹

TaskCommandDescription
Configure usernamegit config --global user.name "<name>"Sets the username for all repositories on your system.
Configure emailgit config --global user.email "<email>"Sets the email address for all repositories on your system.
Configure default text editorgit config --global core.editor <editor>Sets the default text editor for Git commands.
View configuration settingsgit config --listDisplays all Git configuration settings.
Configure line ending conversionsgit config --global core.autocrlf <true/false/input>Configures automatic conversion of line endings (CRLF/LF).

Creating Repositoriesโ€‹

TaskCommandDescription
Initialize a new repositorygit initInitializes a new Git repository in the current directory.
Clone an existing repositorygit clone <repository_url>Creates a copy of an existing Git repository.
Clone a repository to a specific foldergit clone <repository_url> <folder_name>Clones a repository into a specified directory.

Staging and Committingโ€‹

TaskCommandDescription
Check repository statusgit statusShows the working directory and staging area status.
Stage a filegit add <file_name>Adds a file to the staging area.
Stage all filesgit add .Adds all changes in the current directory to the staging area.
Commit changesgit commit -m "<commit_message>"Commits the staged changes with a message.
Commit with a detailed messagegit commitOpens the default editor to write a detailed commit message.
Skip staging and commit directlygit commit -a -m "<commit_message>"Stages all modified files and commits them with a message.
Amend the last commitgit commit --amendModifies the last commit with additional changes or a new commit message.

Branching and Mergingโ€‹

TaskCommandDescription
List all branchesgit branchLists all local branches.
Create a new branchgit branch <branch_name>Creates a new branch without switching to it.
Create and switch to a new branchgit checkout -b <branch_name>Creates and switches to a new branch.
Switch to an existing branchgit checkout <branch_name>Switches to the specified branch.
Delete a branchgit branch -d <branch_name>Deletes the specified branch (only if merged).
Force delete a branchgit branch -D <branch_name>Forcefully deletes the specified branch.
Merge a branch into the current branchgit merge <branch_name>Merges the specified branch into the current branch.
Abort a mergegit merge --abortAborts the current merge and resets the branch to its pre-merge state.
Rebase the current branchgit rebase <branch_name>Reapplies commits on top of another base branch.

Remote Repositoriesโ€‹

TaskCommandDescription
Add a remote repositorygit remote add <name> <url>Adds a new remote repository with the specified name.
View remote repositoriesgit remote -vDisplays the URLs of all remotes.
Remove a remote repositorygit remote remove <name>Removes the specified remote repository.
Rename a remote repositorygit remote rename <old_name> <new_name>Renames a remote repository.
Fetch changes from a remote repositorygit fetch <remote>Downloads objects and refs from another repository.
Pull changes from a remote repositorygit pull <remote> <branch>Fetches and merges changes from the specified branch of a remote repository into the current branch.
Push changes to a remote repositorygit push <remote> <branch>Pushes local changes to the specified branch of a remote repository.
Push all branches to a remotegit push --all <remote>Pushes all branches to the specified remote.
Push tags to a remote repositorygit push --tagsPushes all tags to the specified remote repository.

Inspecting and Comparingโ€‹

TaskCommandDescription
View commit historygit logShows the commit history for the current branch.
View a simplified commit historygit log --oneline --graph --allDisplays a compact, graphical commit history for all branches.
Show commit detailsgit show <commit_hash>Shows the changes introduced by a specific commit.
Compare branchesgit diff <branch_1> <branch_2>Shows differences between two branches.
Compare staged and working directorygit diff --stagedShows differences between the staging area and the last commit.
Compare changes with the last commitgit diff HEADCompares the working directory with the latest commit.

Undoing Changesโ€‹

TaskCommandDescription
Revert changes in a filegit checkout -- <file_name>Discards changes in the working directory for a specific file.
Reset staging areagit reset <file_name>Removes a file from the staging area without changing the working directory.
Reset to a specific commitgit reset --hard <commit_hash>Resets the working directory and staging area to the specified commit, discarding all changes.
Soft reset to a commitgit reset --soft <commit_hash>Resets the staging area to the specified commit, keeping changes in the working directory.
Revert a commitgit revert <commit_hash>Creates a new commit that undoes the changes of a specified commit.
Remove untracked filesgit clean -fRemoves untracked files from the working directory.
Remove untracked directoriesgit clean -fdRemoves untracked directories and their contents from the working directory.

Taggingโ€‹

TaskCommandDescription
List all tagsgit tagLists all tags in the repository.
Create a new taggit tag <tag_name>Creates a new lightweight tag.
Create an annotated taggit tag -a <tag_name> -m "<message>"Creates a new annotated tag with a message.
Show tag detailsgit show <tag_name>Displays details about the specified tag.
Delete a taggit tag -d <tag_name>Deletes the specified tag locally.
Push a tag to a remote repositorygit push <remote> <tag_name>Pushes a tag to the specified remote repository.
Push all tags to a remote repositorygit push --tagsPushes all local tags to the remote repository.
Delete a tag from a remote repositorygit push <remote> :refs/tags/<tag_name>Deletes a tag from the specified remote repository.

Stashingโ€‹

TaskCommandDescription
Stash changesgit stashStashes current changes in the working directory and staging area.
List all stashesgit stash listDisplays a list of all stashes.
Apply a stashgit stash apply <stash_name>Applies a specific stash to the working directory.
Apply and drop a stashgit stash pop <stash_name>Applies the latest stash and removes it from the stash list.
Drop a stashgit stash drop <stash_name>Removes a specific stash from the stash list.
Clear all stashesgit stash clearRemoves all stashes from the stash list.

Submodulesโ€‹

TaskCommandDescription
Add a submodulegit submodule add <repository_url> <path>Adds a submodule to the repository.
Initialize submodulesgit submodule initInitializes local configuration for submodules.
Update submodulesgit submodule updateFetches and checks out the latest changes in submodules.
View submodule statusgit submodule statusDisplays the status of submodules.
Deinitialize a submodulegit submodule deinit <path>Deinitializes a submodule and removes its working directory.

Miscellaneousโ€‹

TaskCommandDescription
View Git versiongit --versionDisplays the currently installed version of Git.
View help for a commandgit <command> --helpShows the help manual for a specific Git command.
View a summary of changesgit shortlogSummarizes commits by author.
Create a Git archivegit archive --format=zip --output=<file.zip> <branch>Creates a compressed archive of a repository.
Reapply changes from another branchgit cherry-pick <commit_hash>Applies changes from a specific commit to the current branch.
Rebase interactivelygit rebase -i <base_commit>Allows for interactive rebasing, which lets you reorder, squash, or drop commits.

Useful Aliasesโ€‹

AliasCommandDescription
git histgit log --oneline --graph --all --decorateShows a pretty and concise graph of the commit history.
git lggit log --graph --pretty=oneline --abbrev-commit --decorate --allA compact view of the commit history.
git stgit statusShortcut for viewing the current status.
git cigit commit -mShortcut for committing with a message.
git cogit checkoutShortcut for switching branches or restoring files.

This guide provides a solid foundation for working with Git, whether you're just getting started or need a quick reference for more advanced tasks.