Git 🔥#
You want to use Git as a real chad developper? Let’s go - f a s t - then.
Basics#
Git is a decentralized versioning tool aimimg to help programmers following source code development.
- Track file changes
- Update remote code
- Work simultaneously with a lot of people
- Arrange your code organization
Resources:
- https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/
- https://rogerdudler.github.io/git-guide/
- https://lab.github.com/lmachens/git-and-github-first-timers
Create a new project#
From scratch#
1git init
From an empty repository#
1git clone https://myrepo.org/project-0
2# or with ssh (use your public key)
3git clone git@myrepo.org:username/project-0
Do some modifications#
"In your favorite editor". Next line: vim 🤣 pic.twitter.com/vw7cqCOFFL
— Baptiste Robert (@fs0c131y) April 28, 2021
1vim my_file.txt # haha 🤣 lol my favorite editor
2# add the file to the repository
3git add my_file.txt
4
5# change the name of the file
6git mv my_file.txt README.md
7
8# delete a file
9git rm README.md
10
11# commit your changes
12git commit -m 'My changes'
13
14# update the repository
15git push
16# if from scratch
17git remote add origin git@myrepo.org:username/project-0
18git push -u origin master
Update your repository#
1git pull
Advanced mechanics#
1# create new branch and push it to repo
2git checkout -b my-branch
3vim ...; git add ...; git commit ...
4git push -u origin my-branch
5
6# tag a commit
7git tag -a v1.0 -m "My description of the tag"
8
9# merge my-branch into master
10git checkout master
11git merge my-branch
12git push
13
14# update your submodules
15git submodule update --remote --merge
16
17# delete a local commit
18git reset HEAD~
19
20# modify a local commit
21git commit --amend
22
23# temporary discard your local changes
24git stash
25
26# config your git variables
27git config user.name PouetPouet
28
29# sign off a commit
30# some opensource project require you to sign your commits, see
31# https://stackoverflow.com/a/1962112
32git commit -s -m "My commit message"
33
34# mutli authors
35git commit -m "My commit message
36You can add co-authors to a commit by adding one line by author like so:
37(note the mandatory 2 empty lines)
38
39
40Co-authored-by: username <user@example.com>"
For more tricks: ohshitgit.com