Skip to content

Instantly share code, notes, and snippets.

@luckysitara
Last active June 23, 2025 08:38
Show Gist options
  • Select an option

  • Save luckysitara/0111d1ae9e072c35fd13b31c59d61d06 to your computer and use it in GitHub Desktop.

Select an option

Save luckysitara/0111d1ae9e072c35fd13b31c59d61d06 to your computer and use it in GitHub Desktop.

Revisions

  1. luckysitara revised this gist Jun 23, 2025. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions git_cheat.md
    Original file line number Diff line number Diff line change
    @@ -87,6 +87,11 @@ echo $PATH

    If not, do the following based on your shell:

    ## To know your which shell you're using use
    ```bash
    echo $SHELL
    ```

    #### If you're using **Bash**:

    ```bash
  2. luckysitara revised this gist Jun 13, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_cheat.md
    Original file line number Diff line number Diff line change
    @@ -190,7 +190,7 @@ From any Git project directory:
    ```bash
    push "updating README with new section"
    ```

    replace "updating README with new section" with your commit message
    ---

    ## 🧠 Summary of What This Does:
  3. luckysitara revised this gist Jun 13, 2025. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion git_cheat.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@

    ---


    ## βœ… GIT ADD ., GIT COMMIT, GIT PUSH CHEAT

    ---

    ## πŸ”§ Option A

    ### 🧱 Step 1: Create Your Script

    1. Open a terminal.
    @@ -119,7 +122,7 @@ You should see:

    ---

    ## πŸ”§ Option A (Recommended): Use a Shell Alias
    ## πŸ”§ Option B (Recommended): Use a Shell Alias

    let’s enhance your workflow by:

  4. luckysitara revised this gist Jun 13, 2025. 1 changed file with 80 additions and 4 deletions.
    84 changes: 80 additions & 4 deletions git_cheat.md
    Original file line number Diff line number Diff line change
    @@ -119,10 +119,86 @@ You should see:

    ---

    ## πŸ’‘ Optional Tips
    ## πŸ”§ Option A (Recommended): Use a Shell Alias

    let’s enhance your workflow by:

    1. βœ… Creating a script that also shows `git status` after push
    2. βœ… Creating a global **alias** named `push` so you don’t have to move or chmod anything manually.

    ---

    ### 🧱 Step 1: Create the Bash Function Alias

    Open your shell config file:

    * For **Bash**:

    ```bash
    nano ~/.bashrc
    ```
    * For **Zsh**:

    ```bash
    nano ~/.zshrc
    ```

    ### 🧩 Step 2: Add This Function Alias

    Paste this **at the bottom** of the file:

    ```bash
    function push() {
    if [ $# -eq 0 ]; then
    echo "❌ Usage: push \"your commit message\""
    return 1
    fi

    local commit_message="$*"

    echo "πŸ“ Staging changes..."
    git add .

    echo "πŸ“ Committing..."
    git commit -m "$commit_message"

    echo "πŸš€ Pushing to remote..."
    git push

    echo "πŸ“Š Status:"
    git status

    echo "βœ… Done!"
    }
    ```

    ### πŸ”„ Step 3: Apply Changes

    ```bash
    source ~/.bashrc # or ~/.zshrc
    ```

    ---

    ### βœ… Step 4: Use It Anywhere

    From any Git project directory:

    ```bash
    push "updating README with new section"
    ```

    ---

    ## 🧠 Summary of What This Does:

    * βœ… Adds all changes: `git add .`
    * βœ… Commits with your message
    * βœ… Pushes to the current branch
    * βœ… Displays `git status` to confirm what’s left (if anything)

    ---


    * Add a `git status` or `git log -1` if you want to confirm the commit.
    * Add error handling for `git` commands if you want more robustness.
    * You can also create aliases or extend this to handle branches.

    ---
  5. luckysitara renamed this gist Jun 13, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. luckysitara created this gist Jun 13, 2025.
    128 changes: 128 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,128 @@

    ---

    ## βœ… GIT ADD ., GIT COMMIT, GIT PUSH CHEAT

    ---

    ### 🧱 Step 1: Create Your Script

    1. Open a terminal.

    2. Run this to create the script file:

    ```bash
    nano push
    ```

    3. Paste the following content:

    ```bash
    #!/bin/bash

    # Check if a commit message is provided
    if [ $# -eq 0 ]; then
    echo "❌ Usage: push \"your commit message\""
    exit 1
    fi

    # Combine all arguments into one commit message
    commit_message="$*"

    echo "πŸ“ Staging changes..."
    git add .

    echo "πŸ“ Committing changes..."
    git commit -m "$commit_message"

    echo "πŸš€ Pushing to remote..."
    git push

    echo "βœ… Done!"
    ```

    4. Save and exit:

    * Press `CTRL+O`, then `ENTER` to save.
    * Press `CTRL+X` to exit.

    ---

    ### πŸ” Step 2: Make the Script Executable

    Run:

    ```bash
    chmod +x push
    ```

    ---

    ### πŸ“‚ Step 3: Create a Local Bin Directory (if it doesn’t exist)

    ```bash
    mkdir -p ~/.local/bin
    ```

    ---

    ### 🚚 Step 4: Move the Script to Your Local Bin

    ```bash
    mv push ~/.local/bin/
    ```

    ---

    ### πŸ› οΈ Step 5: Add `~/.local/bin` to Your PATH

    #### Check if it's already in your PATH:

    ```bash
    echo $PATH
    ```

    If not, do the following based on your shell:

    #### If you're using **Bash**:

    ```bash
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    ```

    #### If you're using **Zsh**:

    ```bash
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    ```

    ---

    ### βœ… Step 6: Test It!

    Go to any Git-tracked folder and run:

    ```bash
    push "your commit message here"
    ```

    You should see:

    ```
    πŸ“ Staging changes...
    πŸ“ Committing changes...
    πŸš€ Pushing to remote...
    βœ… Done!
    ```

    ---

    ## πŸ’‘ Optional Tips

    * Add a `git status` or `git log -1` if you want to confirm the commit.
    * Add error handling for `git` commands if you want more robustness.
    * You can also create aliases or extend this to handle branches.

    ---