Skip to content

Commit e99507c

Browse files
committed
Added Git Notes
1 parent e6ece90 commit e99507c

File tree

2 files changed

+278
-0
lines changed

2 files changed

+278
-0
lines changed

git_cheatsheet.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Git & GitHub Cheat Sheet
2+
3+
A concise, navigable reference for everyday Git tasks, formatted in Markdown.
4+
5+
---
6+
7+
## 1. Configuration
8+
Set your identity once, then verify:
9+
10+
```bash
11+
# Tell Git who you are
12+
git config --global user.name "Your Name"
13+
git config --global user.email "you@example.com"
14+
15+
# List all config settings
16+
git config --list
17+
```
18+
19+
---
20+
21+
## 2. Starting a Repository
22+
23+
### A. Clone an existing repo
24+
```bash
25+
git clone <SSH-or-HTTPS-URL>
26+
cd <repo-folder>
27+
```
28+
29+
### B. Initialize a new repo locally
30+
```bash
31+
git init
32+
```
33+
34+
---
35+
36+
## 3. Remotes
37+
```bash
38+
# Add an “origin” remote for an existing local repo
39+
git remote add origin <SSH-or-HTTPS-URL>
40+
41+
# List configured remotes
42+
git remote -v
43+
44+
# Rename the remote (e.g. from “origin” to “upstream”)
45+
git remote rename origin upstream
46+
```
47+
48+
---
49+
50+
## 4. Checking Status & History
51+
```bash
52+
git status # What’s staged, unstaged, untracked?
53+
git log # Full commit history
54+
git log --oneline --graph --decorate # Compact, visual history
55+
```
56+
57+
---
58+
59+
## 5. Staging & Committing
60+
```bash
61+
git add <file> # Stage a specific file
62+
git add . # Stage all changes in current directory
63+
git commit -m "Msg" # Commit staged changes with message
64+
```
65+
66+
---
67+
68+
## 6. Pushing & Pulling
69+
```bash
70+
# First push: set the upstream (remote + branch) at the same time
71+
git push -u origin main
72+
73+
# Subsequent pushes (working on the same branch):
74+
git push # thanks to -u, you don’t need origin/branch
75+
76+
# Fetch & merge changes from remote
77+
git pull origin main
78+
```
79+
80+
---
81+
82+
## 7. Branching & Checkout
83+
```bash
84+
git branch # List all local branches
85+
git branch -M newName # Rename current branch to newName
86+
git checkout <branch> # Switch to existing branch
87+
git checkout -b <branch> # Create + switch to new branch
88+
git branch -d <branch> # Delete a local branch (if merged)
89+
```
90+
91+
---
92+
93+
## 8. Merging & Diff
94+
```bash
95+
# View diff between your current HEAD and another branch
96+
git diff <branch>
97+
98+
# Merge another branch into your current one
99+
git merge <branch>
100+
```
101+
102+
---
103+
104+
## 9. Undoing & Resetting
105+
> **⚠️ Warning:** Some of these commands rewrite history — use with care!
106+
107+
```bash
108+
# Unstage changes in a file (keeps edits in working directory)
109+
git reset <file>
110+
111+
# Unstage everything
112+
git reset
113+
114+
# Reset to one commit back (moves HEAD to parent)
115+
git reset --mixed HEAD~1 # default; doesn’t touch working files
116+
git reset --soft HEAD~1 # keeps staged changes
117+
git reset --hard HEAD~1 # discards changes in working directory
118+
119+
# Reset to a specific commit (by its hash)
120+
git reset --hard <commit-hash>
121+
```
122+
123+
---
124+
125+
## 10. Quick Tips
126+
127+
- **Amend last commit** (to adjust message or include new staged changes):
128+
```bash
129+
git commit --amend
130+
```
131+
- **Stash unfinished work**:
132+
```bash
133+
git stash # Save local changes
134+
git stash pop # Reapply stashed changes
135+
```
136+
- **Restore a file from the last commit**:
137+
```bash
138+
git restore <file>
139+
```

git_ssh_cheatsheet.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Git & GitHub via SSH – Cheat Sheet
2+
3+
A complete reference for using Git and GitHub **securely via SSH** from the terminal (e.g., Termux).
4+
5+
---
6+
7+
## 1. Initial Configuration
8+
9+
```bash
10+
# Set your identity
11+
git config --global user.name "Your Name"
12+
git config --global user.email "you@example.com"
13+
14+
# Check your configuration
15+
git config --list
16+
```
17+
18+
---
19+
20+
## 2. Generate & Add SSH Key to GitHub
21+
22+
```bash
23+
# Generate a new SSH key
24+
ssh-keygen -t ed25519 -C "you@example.com"
25+
26+
# Start the ssh-agent in the background
27+
eval "$(ssh-agent -s)"
28+
29+
# Add your private key to the ssh-agent
30+
ssh-add ~/.ssh/id_ed25519
31+
32+
# Show your public key
33+
cat ~/.ssh/id_ed25519.pub
34+
```
35+
36+
🔗 Go to [https://github.com/settings/ssh/new](https://github.com/settings/ssh/new) and paste the public key.
37+
38+
---
39+
40+
## 3. Test SSH Connection
41+
42+
```bash
43+
ssh -T git@github.com
44+
```
45+
46+
✅ You should see:
47+
```
48+
Hi username! You've successfully authenticated...
49+
```
50+
51+
---
52+
53+
## 4. Clone Repository (SSH)
54+
55+
```bash
56+
git clone git@github.com:username/repo-name.git
57+
cd repo-name
58+
```
59+
60+
---
61+
62+
## 5. Regular Git Commands (via SSH)
63+
64+
### A. Staging & Committing
65+
```bash
66+
git status # Check changes
67+
git add <file> # Stage a file
68+
git add . # Stage all files
69+
git commit -m "Message" # Commit staged changes
70+
```
71+
72+
### B. Pushing & Pulling
73+
```bash
74+
git push -u origin main # First push with upstream set
75+
git push # Subsequent pushes
76+
git pull origin main # Pull latest changes from GitHub
77+
```
78+
79+
---
80+
81+
## 6. Branching
82+
83+
```bash
84+
git branch # List branches
85+
git checkout <branch> # Switch branch
86+
git checkout -b <branch> # Create + switch
87+
git branch -d <branch> # Delete a local branch
88+
git branch -M new-name # Rename current branch
89+
```
90+
91+
---
92+
93+
## 7. Remote Setup
94+
95+
```bash
96+
# Set remote origin to use SSH
97+
git remote add origin git@github.com:username/repo-name.git
98+
99+
# Verify the remote URL
100+
git remote -v
101+
```
102+
103+
---
104+
105+
## 8. Merging & Diff
106+
107+
```bash
108+
git diff <branch> # See difference from another branch
109+
git merge <branch> # Merge into current branch
110+
```
111+
112+
---
113+
114+
## 9. Undoing & Resetting
115+
116+
```bash
117+
git reset <file> # Unstage a file
118+
git reset # Unstage all files
119+
git reset --mixed HEAD~1 # Reset last commit (keep changes)
120+
git reset --hard HEAD~1 # Reset last commit (discard changes)
121+
git reset --hard <commit-hash># Reset to specific commit
122+
```
123+
124+
---
125+
126+
## 10. Tips & Helpers
127+
128+
```bash
129+
git log # Commit history
130+
git log --oneline --graph # Compact visual history
131+
git restore <file> # Restore file to last commit
132+
git stash # Save uncommitted changes
133+
git stash pop # Reapply saved changes
134+
git commit --amend # Edit last commit
135+
```
136+
137+
---
138+
139+
✅ Now you're set up to use Git and GitHub entirely via SSH!

0 commit comments

Comments
 (0)