An open API service indexing awesome lists of open source software.

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! πŸš€

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! 😊

---