Skip to main content

Git Command

 

Basic Git Commands

  1. Initialize a Repository

    git init

    Initializes a new Git repository in the current directory.

  2. Clone a Repository

    git clone <repository-url>

    Copies a remote repository to your local machine.

  3. Check Repository Status

    git status

    Displays the current state of the working directory and staging area.

  4. Add Files to Staging

    git add <file> git add .

    Stages changes for commit. Use . to stage all changes.

  5. Commit Changes


    git commit -m "Commit message"

    Saves changes to the repository with a descriptive message.

  6. View Commit History

    git log git log --oneline

    Shows a list of commits. Use --oneline for a compact view.


Branching and Merging

  1. Create a New Branch

    git branch <branch-name>

    Creates a new branch.

  2. Switch to a Branch


    git checkout <branch-name>

    Moves to the specified branch.

  3. Create and Switch to a Branch

    git checkout -b <branch-name>

    Creates a new branch and switches to it.

  4. Merge a Branch

    git merge <branch-name>

    Combines changes from the specified branch into the current branch.

  5. Delete a Branch

    git branch -d <branch-name>

    Deletes a branch (if merged). Use -D to force delete.


Remote Repositories

  1. Add a Remote Repository

    git remote add origin <repository-url>

    Links a remote repository.

  2. View Remote Repositories

    git remote -v

    Lists remote repositories.

  3. Push Changes

    git push origin <branch-name>

    Uploads commits to the remote repository.

  4. Pull Changes

    git pull origin <branch-name>

    Fetches and integrates changes from the remote repository.

  5. Fetch Changes

    git fetch origin

    Downloads changes without merging them.


Undoing Changes

  1. Unstage Changes


    git reset <file>

    Removes a file from the staging area.

  2. Revert a Commit


    git revert <commit-hash>

    Creates a new commit to undo changes from a specific commit.

  3. Reset to a Previous Commit


    git reset --hard <commit-hash>

    Resets the repository to a specific commit (deletes changes).


Stashing Changes

  1. Stash Changes

    git stash

    Saves uncommitted changes for later.

  2. Apply Stash


    git stash apply

    Restores stashed changes.

  3. View Stashes

    git stash list

    Lists all stashes.

  4. Drop a Stash


    git stash drop

    Deletes a stash.


Advanced Commands

  1. View Differences

    git diff

    Shows changes between commits, branches, or the working directory.

  2. Tagging a Commit

    git tag <tag-name>

    Adds a tag to a specific commit.

  3. Rebase a Branch

    git rebase <branch-name>

    Reapplies commits from one branch onto another.

  4. Squash Commits

    git rebase -i <commit-hash>

    Combines multiple commits into one.

Comments

Popular posts from this blog

Laravel Interview Question and Answer?

 Here’s a high-level list of Laravel interview questions and answers to help you prepare: 1. What is Laravel? Answer: Laravel is an open-source PHP framework based on the MVC (Model-View-Controller) architectural pattern. It provides an elegant syntax and tools for web application development, including routing, authentication, sessions, and caching. 2. What are the key features of Laravel? Answer: Eloquent ORM : Provides a simple ActiveRecord implementation for database operations. Routing : Simplifies the process of defining routes. Blade Template Engine : A lightweight templating engine with features like template inheritance and sections. Middleware : Filters HTTP requests entering your application. Artisan CLI : Command-line interface for automating tasks. Authentication and Authorization : Built-in user authentication and role-based access control. Queues and Jobs : For task scheduling and background processing. Event Broadcasting : Real-time event broadcasting using WebSock...

how to used redis in Laravel?

 Using Redis in a Laravel application is straightforward because Laravel includes built-in support for Redis. Here's how to integrate and use Redis in Laravel: 1. Install Redis and PHP Redis Extension a. Install Redis Server Install Redis on your server or local environment: bash # For Ubuntu sudo apt update sudo apt install redis # Start Redis service sudo systemctl start redis b. Install PHP Redis Extension Install the PHP extension for Redis: bash # For Ubuntu sudo apt install php-redis c. Verify Redis Installation Check if Redis is running: bash redis-cli ping # Output: PONG 2. Install Laravel Redis Package Laravel uses the predis/predis package or PHP Redis extension to interact with Redis. If you want to use Predis, install it via Composer: bash composer require predis/predis 3. Configure Redis in Laravel Laravel’s Redis configuration is located in the config/database.php file under the redis key. Example Redis Configuration: php 'redis' => [ 'cli...