v2.1 by George Litos
a bit of history cont’d
As with most other distributed version control systems, and unlike most client–server systems, every Git directory on every computer is a full-fledged repository with complete history and full version-tracking abilities, independent of network access or a central server.
Git is free and open-source software distributed under the GPL-2.0-only license.Git is alive
SO Survey 2021
Over 90% of respondents use Git, suggesting that it is a fundamental tool to being a developer.
SO Survey 2022
No other technology is as widely used as Git. Especially among Professional Developers.
Q: What are the primary version control systems you use?
Working directory - repo | the working directory is the folder on your system that you want to track. Where you develop your project. Everything git related is inside the .git folder. Serverless. |
Remote repository | Remote repositories are versions of your project that are hosted elsewhere. You can have several of them, each one is either RO or RW for you. |
Git files | Inside the working directory and beneath, you might find some git related files |
.gitattributes | how to handle files |
.gitignore | what to ignore |
.gitkeep | keep an empty dir |
.
.
.
(not really git)
.
Install git, then
git config --global user.name "John Smith"
git config --global user.email john@example.com
git config --global init.defaultBranch main
Create a new folder for your project and add a file under version control
mkdir -p ~/projects/git-test
cd ~/projects/git-test
git init
nano new_file
git add .
Commit the changes
$ git commit -m "Initial commit"
[master (root-commit) 19632d1] Add new file
1 file changed, 1 insertion(+)
create mode 100644 new-file
every commit is unique, it contains:
a snapshot of the project (a tree with a compressed blob for each file), user information, date, commit message, SHA-1 checksum.$ git log
commit 81752cd6a514fd2595c40f27c783d6887f84e6e6
Author: John Smith <john@example.com>
Date: Thu Apr 7 15:17:45 2022 +0000
Initial commit
Merge Requests
Code Review
CI/CD 🤖 (coming soon…)
Contribute to open source
Be famous 💰
reboot
install docker
git clone repo
cat README.md
> follow the instructions
….you don’t need a server
git init
git commit -a -m 'Commit message'
git checkout -b new_branch
git status
When you don’t know what to do type:
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: docker-compose.yml
Untracked files:
(use "git add <file>..." to include in what will be committed)
.idea/
db_sink/
file_records/
record_transformer/
no changes added to commit (use "git add" and/or "git commit -a")
(e.g. Jetbrains PhpStorm)
g=git
ga='git add'
gl='git pull'
gp='git push'
gcam='git commit -a -m'
gcd='git checkout $(git_develop_branch)'
gdcw='git diff --cached --word-diff'
gfa='git fetch --all --prune --jobs=10'
ggpush='git push origin "$(git_current_branch)"'
gloga='git log --oneline --decorate --graph --all'
grup='git remote update'
gsps='git show --pretty=short --show-signature'
gst='git status'
gstl='git stash list'
gswd='git switch $(git_develop_branch)'
git cherry-pick
lets you select a commit from a branch to apply it to another branch.git tag 1.0.0 -m 'Release 1.0.0'
git stash
allows you to save the current state of the local repository and restore it later.git format-patch
command is useful to transfer a commit
to another repositorySee how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope>
is optional
feat: add hat wobble
^--^ ^------------^
| |
| +-> Summary in present tense.
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test.
feat
: (new feature for the user, not a new feature for build script)fix
: (bug fix for the user, not a fix to a build script)docs
: (changes to the documentation)style
: (formatting, missing semi colons, etc; no production code change)refactor
: (refactoring production code, eg. renaming a variable)test
: (adding missing tests, refactoring tests; no production code change)chore
: (updating grunt tasks etc; no production code change)References:
Pro Git by Scott Chacon and Ben Straub
Git Succinctly by Ryan Hodson
man git
git help <command>