Skip to content

Commit 630f3de

Browse files
committed
docs: add Git commands memo
Add Git commands list used to create this repository
1 parent c18c8b4 commit 630f3de

File tree

1 file changed

+253
-0
lines changed

1 file changed

+253
-0
lines changed

Diff for: docs/git-commands-memo-for-this-repo.md

+253
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
# Git commands memo for the _"Dr. Nord's Hello World in C++"_ repository
2+
3+
A command set used to create this repository (using the Bash command shell).
4+
Might be useful for beginners to master Git and GitHub.
5+
6+
Copyright (C) 2021 Dr. Nord
7+
8+
#### Create a repository on GitHub
9+
Name:
10+
```
11+
dr-nord-s-hello-world-in-cpp
12+
```
13+
About:
14+
```
15+
Dr. Nord's Hello World in C++: the beginner's project with explanatory comments and support files including documentation and useful links.
16+
```
17+
Topics:
18+
```
19+
c-plus-plus example project beginners informative
20+
```
21+
#### Create a local repository
22+
23+
```
24+
git init
25+
```
26+
27+
#### Add description of the repository
28+
```
29+
printf "Dr. Nord's Hello World in C++" > .git/description
30+
```
31+
32+
#### Setup digital signature (optional)
33+
If you want to reproduce this steps you need to generate a public/private key-pair and configure Git to sign commits.
34+
- Set auto-sign commits and tags for current repository
35+
```
36+
git config commit.gpgsign true
37+
git config tag.gpgsign true
38+
```
39+
- Set a default public key ID (or a full 40-character fingerprint)
40+
```
41+
git config user.signingkey FBEAEFB56F021E9A17F53C4B01193969593B7668
42+
```
43+
44+
45+
### Version 1.0.0 creation
46+
47+
#### Stage (index) the source code file
48+
```
49+
git add main.cpp
50+
```
51+
52+
#### Initial commit
53+
```
54+
git commit -m "feat: initial commit of source code"
55+
```
56+
57+
#### Stage and commit (hereinafter 'add' or 'update' context dependent) support files
58+
```
59+
git add .gitignore makefile
60+
git commit -m "feat: add support files" -m "Add '.gitignore' and 'makefile'"
61+
```
62+
63+
#### Add documentation
64+
```
65+
git add LICENSE-MIT.txt README.md docs/\*
66+
git commit -m "docs: initial documentation" -m "Add Readme, licenses, Contribution Guide and Code of Conduct"
67+
```
68+
69+
#### Add templates for GitHub
70+
```
71+
git add .github/\*
72+
git commit -m "docs: add GitHub templates" -m "Add templates for Issues and Pull Requests"
73+
```
74+
75+
#### Add an annotated tag to the last commit (v1)
76+
```
77+
git tag -a v1.0.0 -m "classic"
78+
```
79+
80+
#### Create and add changelog
81+
```
82+
git tag -l $(git describe) --format='%(taggerdate:short) Release: %(tag)-%(contents:subject)%0A' > CHANGELOG.md
83+
git log --pretty=" - %s%n%n %b" >> CHANGELOG.md
84+
git add CHANGELOG.md
85+
git commit -m "docs: add changelog"
86+
```
87+
88+
#### Move the last tag
89+
```
90+
git tag -d v1.0.0
91+
git tag -a v1.0.0 -m "classic"
92+
```
93+
or
94+
```
95+
git tag -af v1.0.0 -m "classic"
96+
```
97+
98+
#### Add GitHub repository url to the list of servers under 'origin' name, check the result
99+
```
100+
git remote add origin https://github.com/DrNord/dr-nord-s-hello-world-in-cpp.git
101+
git remote -v
102+
```
103+
104+
#### Push to remote repository (forced) with tags
105+
```
106+
git push origin main -f --tags
107+
```
108+
109+
**Manually create a release in GitHub**:
110+
- in the 'Releases' section click on 'tags'
111+
- switch to 'Tags' tab
112+
- click the three dots sign on the right, the 'Create release' button will appear (click it)
113+
- a new release should be generated from the existing tag, choose a release title ```v1.0.0-classic```
114+
- fill release description:
115+
```
116+
The classic source code, despite its brevity, clarifies the basic structure of a C++ program (run the executable from a command line).
117+
```
118+
- add executable (optional)
119+
<br/>
120+
121+
122+
### Version 2.0.0 creation
123+
124+
#### Change license
125+
- remove license file from tracked list (to leave a file on a disk use an option '--cached')
126+
```
127+
git rm LICENSE-MIT.txt
128+
```
129+
- add new license file (bash uses '!' for history expansion, so use an editor for message forming)
130+
```
131+
git add LICENSE-GNU-GPL.txt
132+
git commit
133+
```
134+
Copy-paste this to your editor:
135+
```
136+
docs!: change license to GNU GPL v3.0 or later
137+
```
138+
139+
#### Add extended source code (bash uses '!' for history expansion, so use an editor for message forming)
140+
```
141+
git add main-x.cpp makefile-x
142+
git commit
143+
```
144+
Copy-paste this to your editor:
145+
```
146+
feat!: implement user input
147+
148+
BREAKING CHANGE: add extended source code 'main-x.cpp' with implemented user input, add 'makefile-x'
149+
```
150+
151+
#### Add Git commands memo
152+
```
153+
git add docs/git-commands-memo-for-this-repo.md
154+
git commit -m "docs: add Git commands memo" -m "Add Git commands list used to create this repository"
155+
```
156+
157+
#### Update Readme
158+
```
159+
git add README.md
160+
git commit -m "docs: update readme" -m "Add information about the extended version"
161+
```
162+
163+
#### Add an annotated tag to the last commit (v2)
164+
```
165+
git tag -a v2.0.0 -m "extended"
166+
```
167+
168+
#### Update changelog
169+
- save old changelog
170+
```
171+
mv CHANGELOG.md CHANGELOG-old.md
172+
```
173+
- create new changelog
174+
```
175+
git tag -l $(git describe) --format='%(taggerdate:short) Release: %(tag)-%(contents:subject)%0A' > CHANGELOG.md
176+
git log v1.0.0..v2.0.0 --pretty=" - %s%n%n %b" >> CHANGELOG.md
177+
```
178+
- add info from old to new changelog
179+
```
180+
cat CHANGELOG-old.md >> CHANGELOG.md
181+
```
182+
- update changelog
183+
```
184+
git add CHANGELOG.md
185+
git commit -m "docs: update changelog"
186+
```
187+
- check for untracked files to delete, if OK - execute deletion
188+
```
189+
git clean -n
190+
git clean -f
191+
```
192+
193+
#### Move the last tag
194+
```
195+
git tag -af v2.0.0 -m "extended"
196+
```
197+
198+
#### Push to remote repository with tags
199+
```
200+
git push origin main --tags
201+
```
202+
203+
**Manually create a release in GitHub**:
204+
- a new release should be generated from the existing tag, choose a release title ```v2.0.0-extended```
205+
- fill release description:
206+
```
207+
The classic source code, despite its brevity, clarifies the basic structure of a C++ program. The extended source code covers additional issues such as copyright, licensing information, user interaction, etc.
208+
```
209+
- add executable (optional)
210+
211+
<br/>
212+
213+
214+
##### Other useful commands
215+
216+
- Commit history
217+
```
218+
git log
219+
```
220+
- Download remote objects and references with tags
221+
```
222+
git fetch --tags
223+
```
224+
- Delete all tags
225+
```
226+
git tag -d $(git tag -l)
227+
```
228+
- Amend the last commit
229+
```
230+
git commit --amend -m "Title" -m "Description"
231+
```
232+
- Delete a remote tag
233+
```
234+
git push --delete origin v1.0.0
235+
```
236+
- Simple changelog (GNU Coding Standards)
237+
cs: short date ISO 8601 - YYYY-MM-DD
238+
cn: committer name
239+
ce: committer e-mail
240+
n: new line
241+
s: commit subject (title)
242+
b: commit body
243+
```
244+
git log --pretty="- %cs %cn <%ce>%n%n %s%n%n %b" > CHANGELOG.md
245+
```
246+
- Commit signature checkout
247+
```
248+
git log --show-signature
249+
```
250+
- Remove parameter
251+
```
252+
git config --unset --global user.name
253+
```

0 commit comments

Comments
 (0)