-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-cheatsheet-gist.txt
More file actions
107 lines (81 loc) · 1.66 KB
/
git-cheatsheet-gist.txt
File metadata and controls
107 lines (81 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Git Cheatsheet: From Basics to Time Travel
A collection of essential Git commands, from daily workflows to digging through the depths of your repository's history.
## 🔍 Searching History
### Find when a file existed (even if deleted)
```bash
git log --all -- [path]
```
### Search for content changes (Pickaxe)
Find commits where a specific string was added or removed:
```bash
git log -S "your_search_string"
```
### Search content with Regex
```bash
git log -G "your_regex"
```
### Find a file in any commit/branch
```bash
git rev-list --all | xargs git grep -l "filename"
```
### See the history of a specific function/method
```bash
git log -L :function_name:file_path
```
---
## 🚀 Daily Workflow
### Stage and Commit
```bash
git add .
git commit -m "feat: descriptive message"
```
### Undo last commit (keep changes)
```bash
git reset --soft HEAD~1
```
### Fix the last commit message
```bash
git commit --amend -m "new message"
```
---
## 🌿 Branching & Merging
### Switch to a new branch
```bash
git checkout -b feature/cool-stuff
# or the newer way:
git switch -c feature/cool-stuff
```
### List all branches (including remote)
```bash
git branch -a
```
### Safely delete a branch
```bash
git branch -d branch_name
```
---
## 🛠️ Cleanup & Maintenance
### Discard all local changes
```bash
git reset --hard HEAD
```
### Clean untracked files
```bash
git clean -fd
```
### Stash changes for later
```bash
git stash save "Work in progress"
git stash list
git stash pop
```
---
## 📤 Remote Operations
### Update local with remote and rebase
```bash
git pull --rebase origin main
```
### Prune old remote tracking branches
```bash
git fetch -p
```