Skip to content

Instantly share code, notes, and snippets.

@dileepadev
Last active October 29, 2025 17:33
Show Gist options
  • Select an option

  • Save dileepadev/023e79623512badbd88f4d6301b8be91 to your computer and use it in GitHub Desktop.

Select an option

Save dileepadev/023e79623512badbd88f4d6301b8be91 to your computer and use it in GitHub Desktop.
Git Commands

Git Commands

Table of Contents

  1. Create a New Repository on the Command Line
  2. Push an Existing Repository from the Command Line
  3. Commit Changes
  4. Commit for Old Dates
  5. Undo Last Commit (Soft Reset)
  6. Show Last 15 Commits in Custom Format
  7. View All Branches
  8. List Local and Remote Branches
  9. View Branch Details
  10. List Remote Branches with Commit Info
  11. Switch to an Existing Branch
  12. Create and Switch to a New Branch
  13. Check Out Specific Commits
  14. Stash Changes
  15. Apply Stashed Changes

Create a New Repository on the Command Line

echo "# return-python" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/dileepadev/return-python.git
git push -u origin main

Push an Existing Repository from the Command Line

git remote add origin https://github.com/dileepadev/return-python.git
git branch -M main
git push -u origin main

Commit Changes

git commit -m "Commit message" -m "Detailed description goes here. You can add multiple lines if needed."
git commit -m "chore: Upgrade dependencies" -m "Including all other packages"

Commit for Old Dates

git commit --date="10 day ago" -m "Your commit message"
git commit --date="2024-01-09 16:00:00" -m "Empty repo files"

Undo Last Commit (Soft Reset)

git reset --soft HEAD~1

Show Last 15 Commits in Custom Format

git log -n 15 --pretty=format:"%ad | %h | %G? | %an | %s" --date=iso
git log -n 15 --pretty=format:"%ad | %h | %G? | %an | %s" --date=iso --author="Dileepa Bandara\|dileepadev
git log -n 15 --pretty=format:"%ad | %h | %G? | %an | %s" --date=iso --author="[email protected]"

View All Branches

git branch -a

List Local and Remote Branches

git branch -r

View Branch Details

git branch -av
git branch -a -v

List Remote Branches with Commit Info

git branch -rv
git branch -r -v

Switch to an Existing Branch

git checkout feature-branch

Create and Switch to a New Branch

git checkout -b <new_branch_name>

Check Out Specific Commits

git checkout <commit_hash>

Stash Changes

git stash
git stash save "Descriptive message about changes"

Apply Stashed Changes

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