# Git Commands ## Table of Contents 1. [Create a New Repository on the Command Line](#create-a-new-repository-on-the-command-line) 2. [Push an Existing Repository from the Command Line](#push-an-existing-repository-from-the-command-line) 3. [Commit Changes](#commit-changes) 4. [Commit for Old Dates](#commit-for-old-dates) 5. [Undo Last Commit (Soft Reset)](#undo-last-commit-soft-reset) 6. [Show Last 15 Commits in Custom Format](#show-last-15-commits-in-custom-format) 7. [View All Branches](#view-all-branches) 8. [List Local and Remote Branches](#list-local-and-remote-branches) 9. [View Branch Details](#view-branch-details) 10. [List Remote Branches with Commit Info](#list-remote-branches-with-commit-info) 11. [Switch to an Existing Branch](#switch-to-an-existing-branch) 12. [Create and Switch to a New Branch](#create-and-switch-to-a-new-branch) 13. [Check Out Specific Commits](#check-out-specific-commits) 14. [Stash Changes](#stash-changes) 15. [Apply Stashed Changes](#apply-stashed-changes) ## Create a New Repository on the Command Line ```shell 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 ```shell git remote add origin https://github.com/dileepadev/return-python.git git branch -M main git push -u origin main ``` ## Commit Changes ```shell 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 ```shell 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) ```shell git reset --soft HEAD~1 ``` ## Show Last 15 Commits in Custom Format ```shell git log -n 15 --pretty=format:"%ad | %h | %G? | %an | %s" --date=iso ``` ```shell git log -n 15 --pretty=format:"%ad | %h | %G? | %an | %s" --date=iso --author="Dileepa Bandara\|dileepadev ``` ```shell git log -n 15 --pretty=format:"%ad | %h | %G? | %an | %s" --date=iso --author="youremail@example.com" ``` ## View All Branches ```shell git branch -a ``` ## List Local and Remote Branches ```shell git branch -r ``` ## View Branch Details ```shell git branch -av git branch -a -v ``` ## List Remote Branches with Commit Info ```shell git branch -rv git branch -r -v ``` ## Switch to an Existing Branch ```shell git checkout feature-branch ``` ## Create and Switch to a New Branch ```shell git checkout -b ``` ## Check Out Specific Commits ```shell git checkout ``` ## Stash Changes ```shell git stash git stash save "Descriptive message about changes" ``` ## Apply Stashed Changes ```shell git stash apply git stash pop ```