https://github.com/shihabshahrier/git-github-command-cheat-sheet
Git is your version control best friend, and GitHub is where collaboration magic happens! Below is a guide to the most useful Git & GitHub commands youβll use daily. Letβs master the flow of commits, branches, and merges! π
https://github.com/shihabshahrier/git-github-command-cheat-sheet
git github github-branches github-config merge-branch
Last synced: 10 months ago
JSON representation
Git is your version control best friend, and GitHub is where collaboration magic happens! Below is a guide to the most useful Git & GitHub commands youβll use daily. Letβs master the flow of commits, branches, and merges! π
- Host: GitHub
- URL: https://github.com/shihabshahrier/git-github-command-cheat-sheet
- Owner: shihabshahrier
- Created: 2025-01-04T17:07:19.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-04T17:13:19.000Z (about 1 year ago)
- Last Synced: 2025-01-26T06:13:18.651Z (about 1 year ago)
- Topics: git, github, github-branches, github-config, merge-branch
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π **Git & GitHub Command Cheat Sheet**
Master Git and GitHub with this comprehensive cheat sheet. From basics to advanced tricks, this guide has everything you need to manage and collaborate on code like a pro! π
---
## π **Getting Started with Git**
### 1. **Check Git Status**
```bash
git status
```
*π View modified, untracked, or staged files in your working directory.*
### 2. **Initialize a Git Repository**
```bash
git init
```
*π Turn a project directory into a Git-tracked repository.*
### 3. **Clone a GitHub Repository**
```bash
git clone
```
*π₯ Copy a remote repository to your local machine.*
---
## π€ **Making Changes Locally**
### 4. **Add Files to Staging Area**
```bash
git add # Add a specific file
git add . # Add everything
```
*π Prepare changes for commit.*
### 5. **Commit Changes**
```bash
git commit -m "Your message"
```
*πΎ Save staged changes with a descriptive message.*
### 6. **Unstage Files**
```bash
git reset
```
*π§ Remove files from staging without discarding changes.*
---
## π³ **Branching & Merging**
### 7. **Create and Switch to a Branch**
```bash
git checkout -b
```
*πΏ Create and move to a new branch in one step.*
### 8. **Merge a Branch**
```bash
git merge
```
*π Combine changes from another branch into your current branch.*
### 9. **Delete a Branch**
```bash
git branch -d
```
*ποΈ Remove a branch you no longer need.*
---
## π **Syncing with GitHub**
### 10. **Push Changes**
```bash
git push origin
```
*π Upload your local branch to the remote repository.*
### 11. **Pull Updates**
```bash
git pull origin
```
*π₯ Fetch and merge changes from the remote branch.*
---
## π§ **Advanced Git Commands**
### 12. **Rebase a Branch**
```bash
git rebase
```
*πͺ Move your branch to start from the latest changes in another branch.*
**Example Workflow:**
1. Switch to the feature branch: `git checkout feature-branch`
2. Rebase onto main: `git rebase main`
*β¨ This creates a cleaner commit history by replaying your commits on top of the target branch.*
---
### 13. **Squash Commits**
```bash
git rebase -i HEAD~
```
*π¦ Combine multiple commits into one to simplify history.*
**Example Workflow:**
1. Use `git rebase -i HEAD~3` to squash the last 3 commits.
2. Mark commits as `squash` or `s` in the interactive editor.
3. Save and exit to merge the commits.
---
### 14. **Cherry-Pick a Commit**
```bash
git cherry-pick
```
*π Apply a specific commit from one branch to another.*
**Example Workflow:**
1. Find the commit hash using `git log`.
2. Apply it to your branch: `git cherry-pick abc1234`.
---
### 15. **Stash Changes Temporarily**
```bash
git stash
```
*π§³ Save your changes for later without committing.*
**Retrieve Stashed Changes:**
```bash
git stash pop
```
*πͺ Apply and remove the latest stash.*
---
### 16. **Amend the Last Commit**
```bash
git commit --amend -m "Updated commit message"
```
*βοΈ Edit the last commit message or add files you forgot to include.*
---
## π **Tracking and Troubleshooting**
### 17. **View Commit History**
```bash
git log
git log --oneline
```
*π View detailed or one-line commit history.*
### 18. **Check File Changes**
```bash
git diff
```
*π Compare changes in a specific file.*
### 19. **Find the Commit That Introduced a Bug**
```bash
git bisect start
git bisect bad
git bisect good
```
*π Automates binary search to pinpoint the bad commit.*
---
## βοΈ **Customizing Git**
### 20. **Set Global User Info**
```bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
```
*π Identify yourself for all repositories.*
### 21. **Alias Common Commands**
```bash
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
```
*β‘ Create shortcuts for frequent commands.*
---
## π **Bonus Tips**
- **Clean Up Old Branches Locally and Remotely**
```bash
git branch -d # Delete local branch
git push origin --delete # Delete remote branch
```
- **Force Pull (Override Local Changes)**
```bash
git fetch origin
git reset --hard origin/
```
*β οΈ Warning: This overwrites your local changes.*
- **Track a Remote Branch Locally**
```bash
git checkout --track origin/
```
*π£ Follows a remote branch for easy pulls and pushes.*
---
## π **Mastering Git Workflow**
1. Create a branch for new features:
```bash
git checkout -b feature/new-feature
```
2. Commit your work:
```bash
git add .
git commit -m "Add new feature"
```
3. Push to GitHub:
```bash
git push origin feature/new-feature
```
4. Open a pull request on GitHub to merge into `main` or `develop`.
---
## β¨ **That's a Wrap!**
Youβre now equipped with beginner and advanced Git skills. Start applying them to your projects, squash your bugs, and keep your commit history neat and clean. πβ¨
Got feedback or more advanced topics you'd like to cover? Let me know! π
---