Git - Cheat Sheet: A Quick Guide to Git Commands
Git, the ubiquitous version control system, empowers developers to efficiently manage their codebase. Whether you're a Git novice or a seasoned pro, having a cheat sheet handy can be a game-changer. Let's explore a comprehensive Git cheat sheet to help you navigate your repositories with ease.
1. Setting Up Git:
- **Configure User Information:**
```
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
```
- **Initialize a Repository:**
```
git init
```
2. Basic Commands:
- **Clone a Repository:**
```
git clone <repository_url>
```
- **Check Repository Status:**
```
git status
```
- **Add Changes to Staging:**
```
git add <file_name>
```
- **Commit Changes:**
```
git commit -m "Your commit message"
```
3. Branching:
- **Create a New Branch:**
```
git branch <branch_name>
```
- **Switch to a Branch:**
```
git checkout <branch_name>
```
- **Merge Branches:**
```
git merge <branch_name>
```
- **Delete a Branch:**
```
git branch -d <branch_name>
```
4. Remote Repositories:
- **Add a Remote Repository:**
```
git remote add origin <repository_url>
```
- **Push to a Remote Repository:**
```
git push -u origin <branch_name>
```
- **Pull Changes from a Remote Repository:**
```
git pull origin <branch_name>
```
5. Undoing Changes:
- **Discard Changes in Working Directory:**
```
git checkout -- <file_name>
```
- **Undo the Last Commit:**
```
git reset --soft HEAD
```
- **Discard Changes in Staging:**
```
git reset <file_name>
```
6. Log and History:
- **View Commit History:**
```
git log
```
- **Show Changes in a Commit:**
```
git show <commit_hash>
```
- **Compare Branches:**
```
git diff <branch1> <branch2>
```
7. Tagging:
- **Create a Lightweight Tag:**
```
git tag <tag_name>
```
- **Create an Annotated Tag:**
```
git tag -a <tag_name> -m "Tag message"
```
- **Push Tags to Remote Repository:**
```
git push origin --tags
```
This Git cheat sheet serves as a quick reference, aiding you in mastering the essential commands for version control. Keep it handy on your desk or bookmarked in your browser for those moments when you need a quick Git command refresher. Happy coding!
Comments
Post a Comment