diff --git a/tech_docs/git_cheat_sheet.md b/tech_docs/git_cheat_sheet.md index 3e5dab9..f8825f1 100644 --- a/tech_docs/git_cheat_sheet.md +++ b/tech_docs/git_cheat_sheet.md @@ -1,3 +1,104 @@ +Certainly! Here’s 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 + ``` + +- **Stage a deleted file:** + ```bash + git rm + ``` + +- **Stage recursive deletion for directories:** + ```bash + git rm -r + ``` + +### 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 "" +``` + +### 4. **Pushing Changes** +To synchronize your local changes with the remote repository: + +```bash +git push origin +``` + +### 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 --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 ## **1. Remote Repository Commands**