Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/dev/git_cheatsheet.md

3.5 KiB, 1 run

created by r1870400018:4028, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1# Git Workflow Cheat Sheet
2
3## 1. Branch Management
4
5### Check Current Status
6```bash
7git status # Show changed files
8git branch # List branches (* shows current)
9git branch --show-current # Just show current branch name
10```
11
12### Creating & Switching Branches
13```bash
14git checkout -b new-branch # Create and switch to new branch
15git checkout existing-branch # Switch to existing branch
16```
17
18### Stashing Changes
19```bash
20git stash # Save current changes
21git stash list # Show all stashes
22git stash pop # Apply and remove most recent stash
23git stash apply stash@{1} # Apply specific stash without removing
24git stash drop stash@{1} # Remove specific stash
25```
26
27## 2. Working with Changes
28
29### Basic Workflow
30```bash
31git status # Check what's changed
32git add specific-file.txt # Stage specific file
33git add . # Stage all changes
34git commit -m "Message" # Commit with message
35```
36
37### Selective Committing
38```bash
39git add -p # Interactively choose parts to stage
40git restore --staged file.txt # Unstage a file
41git diff # Show unstaged changes
42git diff --staged # Show staged changes
43```
44
45### Fixing Mistakes
46```bash
47git reset --soft HEAD^ # Undo last commit, keep changes staged
48git reset --hard HEAD^ # Undo last commit, discard changes
49git restore file.txt # Discard changes in file
50```
51
52## 3. Feature Branch Workflow
53
54### Start New Feature
55```bash
56git checkout main
57git pull # Get latest main
58git checkout -b feature-name # Create feature branch
59```
60
61### Work on Feature
62```bash
63# Make changes
64git add .
65git commit -m "Feature progress"
66git push -u origin feature-name # First push
67git push # Subsequent pushes
68```
69
70### Finish Feature
71```bash
72git checkout main
73git pull # Get any new changes
74git merge feature-name # Merge feature into main
75git push # Push merged changes
76git branch -d feature-name # Delete local branch
77git push origin -d feature-name # Delete remote branch
78```
79
80## 4. Common Scenarios
81
82### Save Work in Progress
83```bash
84git diff > my_changes.patch # Backup changes to file
85git stash # Or use stash
86```
87
88### Handle Merge Conflicts
89```bash
90git status # See conflicted files
91# Edit files to resolve conflicts
92git add resolved-file.txt
93git commit # Complete the merge
94```
95
96### Update Feature Branch with Main
97```bash
98git checkout feature-branch
99git merge main # Get changes from main
100```
101
102## 5. Useful Commands
103
104### View History
105```bash
106git log # Show commit history
107git log --oneline # Compact history view
108git show commit-hash # Show specific commit details
109```
110
111### Remote Operations
112```bash
113git remote -v # Show remote repositories
114git fetch # Get remote changes without merging
115git pull # Get and merge remote changes
116```
117
118### Configuration
119```bash
120git config --global user.name "Your Name"
121git config --global user.email "your.email@example.com"
122```
123
124## 6. Tips
125
126- Always check which branch you're on before making changes
127- Commit frequently with clear messages
128- Pull from main regularly to stay up to date
129- Use feature branches for new work
130- Backup important changes before risky operations
131- Add generated files and build artifacts to .gitignore