Update git_cheat_sheet.md with technical reference guide

This commit is contained in:
2024-05-01 12:49:54 -06:00
parent 2e550840b1
commit 79aa77bfb5

View File

@@ -1,3 +1,104 @@
Certainly! Heres a concise and highly technical reference guide based on our discussion about handling file deletions and commits in Git:
### 1. **Reviewing Changes**
Before making any changes to your Git repository, always check the current status to see untracked or modified files.
```bash
git status
```
### 2. **Staging Changes**
To stage changes, including file deletions or modifications:
- **Stage a specific file:**
```bash
git add <file_path>
```
- **Stage a deleted file:**
```bash
git rm <file_path>
```
- **Stage recursive deletion for directories:**
```bash
git rm -r <directory_path>
```
### 3. **Committing Changes**
After staging the changes, commit them with a clear and descriptive message. The message should concisely explain the what and why of the changes.
```bash
git commit -m "<commit_message>"
```
### 4. **Pushing Changes**
To synchronize your local changes with the remote repository:
```bash
git push origin <branch_name>
```
### 5. **Handling Divergent Branches**
If you encounter a message about divergent branches during a pull, you have several options to reconcile them:
- **Merge (creates a merge commit):**
```bash
git pull --rebase=false
```
- **Rebase (reapplies local commits on top of fetched commits):**
```bash
git pull --rebase=true
```
- **Fast-forward only (rejects non-fast-forward pulls):**
```bash
git pull --ff-only
```
### 6. **Force-Pushing Changes**
To overwrite remote changes with your local branch (use with caution):
```bash
git push origin <branch_name> --force
```
### 7. **Best Practices for Commit Messages**
- Keep the subject line around 50 characters.
- Use the body to explain "what" and "why", not "how".
- Use imperative mood in the subject line.
### 8. **Ignoring Files**
To prevent tracking of unnecessary files like `.DS_Store`, create a `.gitignore` file:
- **Example `.gitignore` content:**
```
.DS_Store
```
### 9. **Git Configuration for Handling Pulls**
Set a global preference for how pulls are handled across all repositories:
- **For merging:**
```bash
git config --global pull.rebase false
```
- **For rebasing:**
```bash
git config --global pull.rebase true
```
- **For fast-forward only:**
```bash
git config --global pull.ff only
```
This guide consolidates the key actions and commands in Git related to staging, committing, and pushing changes, along with best practices and configuration tips. Use it as a technical reference to manage your projects effectively in Git.
---
# Git Cheatsheet # Git Cheatsheet
## **1. Remote Repository Commands** ## **1. Remote Repository Commands**