save file to computer -- like writing a letter
add file to the staging area -- like putting a letter into an envelope
keeps track of changes
commit -- like actually sealing and posting the envelope
snapshot of the files at that moment in time
commit
metadata
hashed identifier
author
log message
commit timestamp
tree
locations
directories
files
names
blob (binary large object)
data of any kind
compressed snapshot of the file's content
Branches are alternative versions of one repository. The are used for parallel work in different parts of the same project. The project's files can be:
equal in branches
different in branches
not existing in branches
Every repository has and starts with the main branch.
Branches should be feature specific with a unique purpose.
A repository is a collection of folders and files. That is where Git stores its data for a project.
repository
remote repository
stored in the cloud via a service, e.g. GitHub
local repository
stored on the local computer
clone
depended copy
linked copy on a local computer
uses git
push and pull updates with git
fork
independent copy
in GitHub
done in GitHub
needs pull request
saver for experimentation
git add
git add my_file.txt adds my_file.txt to the staging area
git add . adds all files and subdirectories to git staging area
git commit commits to the staging area
git commit -m "myUploadComment" commit to git, with a descriptive comment as additional message
git init creates and empty repository in the directory and wants to track files
git init my_project_name create a new git repository in the new directory "my_project_name"
git --version gets git version
git diff
git diff my_file.txt compares the last committed version and the new version outside the staging area
git diff --staged my_file.txt compares the last committed version and the new version inside the staging area
git diff --staged compares all staged files to their committed versions
git diff hash_1 hash_2 compares to files by their commit hash (put most recent hash second)
git diff HEAD~1 HEAD compares the latest to the second latest commit
git log shows all past git commits in descending order
git log -n show n last commits
git log my_file.txt shows only commits for my_file.txt
git log -n my_file.txt shows only the last n commits for my_file.txt
git log --since="YYYY-MM-DD" limit the log to a start date
git log --until="YYYY-MM-DD" limit the log to an end date
git log --since="YYYY-MM-DD" --until="YYYY-MM-DD" limit the log to a time period
Furthermore, dates can be given as "2 weeks ago", "3 month ago", "yesterday", and different date formats etc.
git show hash_begin shows all commits and differences that start with hash_begin
git status see git's status
git checkout HEAD -- my_file.txt checks my_file.txt from the latest commit
git reset undo git add
git restore
git restore --stage un-stages all files in the staging area
git restore --stage my_file.txt un-stages my_file.txt from the staging area
git revert HEAD updates to the most recent commit
NB Revert reverts to the full commit will all files in it!
git revert--no-edit HEAD updates to the most recent commit while skipping the comment editor
git revert hash updates to the former commit with the hash
git revert -n HEAD does not commit the changes, but get it into the staging area
git branch shows branches, current marked with *
git branch my_new_branch creates a new branching repository with the name my_new_branch
git -m ranch my_old_name my_new_name renames a branch with m [sic!]
git branch -d my_branch deletes the branched repository my_branchgit
git switch
git switch my_new_branch switches to the branched repository with the name my_new_branch
git switch -c my_new_branch creates a new branch and switches to it
git switch main change to main branch repository
git diff
git diff main my_other_branch compares my branch to my main repository
get into the destination branch you want to merge to
git merge
git merge source_branch merges the source branch to the main branch
git merge source_branch destination_branch merges source with destination
git merge origin synchronises origin's main branch to the current local branch
git merge my_branch --ff-only fast-forward merge, and preset standard anyhow
a fast forward merge keeps thinks simple and linear in short time feature branches
git merge --no-ff my_branch recursive merge i.e. with two parents
a recursive merge is complex, but shows full history in longtime project branches
git clone /home/path…/… clones a reprository from its path
git clone /home/path…/… new_name clones a reprository from its path under new_reprository_name
git clone URL clones a reprository from a URL to the local computer
git fetch origin fetches all branches from the remote remote to the local repository
git fetch origin main fetches the main branch from the remote remote to the local repository
git merge origin synchronises origin's main branch to the current local branch
git pull origin pull files from git i.e. fetches and merges the main remote main branch to the current local branch at same time
git pull origin my_branch pull files from my_branch to the local current branch
git push remote my_local_branch pushes my_local_branch to the remote repository
git push origin main pushes the local main branch to the remote origin
git remote lists remote viz. cloned repositories
git remote -v lists more detailed, verbose about remote viz. cloned repositories
git remote add new_name URL renames the repository belonging to the URL
pull request (PR)
base branch to add to
compare brach to add from