Skip to content

Instantly share code, notes, and snippets.

@luckysitara
Last active June 23, 2025 08:38
Show Gist options
  • Save luckysitara/0111d1ae9e072c35fd13b31c59d61d06 to your computer and use it in GitHub Desktop.
Save luckysitara/0111d1ae9e072c35fd13b31c59d61d06 to your computer and use it in GitHub Desktop.

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


πŸ”§ Option A

🧱 Step 1: Create Your Script

  1. Open a terminal.

  2. Run this to create the script file:

    nano push
  3. Paste the following content:

    #!/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:

chmod +x push

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

mkdir -p ~/.local/bin

🚚 Step 4: Move the Script to Your Local Bin

mv push ~/.local/bin/

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

Check if it's already in your PATH:

echo $PATH

If not, do the following based on your shell:

To know your which shell you're using use

echo $SHELL

If you're using Bash:

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

If you're using Zsh:

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

βœ… Step 6: Test It!

Go to any Git-tracked folder and run:

push "your commit message here"

You should see:

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

πŸ”§ Option B (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:

    nano ~/.bashrc
  • For Zsh:

    nano ~/.zshrc

🧩 Step 2: Add This Function Alias

Paste this at the bottom of the file:

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

source ~/.bashrc     # or ~/.zshrc

βœ… Step 4: Use It Anywhere

From any Git project directory:

push "updating README with new section"

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

🧠 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)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment