Git
git
can simply be considered a distrubuted version control system.
It basically keeps track of files on your computer but potentially remote servers as well (like gitlab,github,etc.).
How it works¶
flowchart TB
add(Live) -- git add --> stage(Staged)
stage -- git commit --> commit(Committed)
stage -- git restore --staged --> add
commit -- git reset --soft --> stage
commit -- git push --> push(Pushed)
Adding changes (man page)¶
Committing (man page)¶
Be verbose about what changes happened since your last commit. Your future self will thank you.
Pushing changes to remote (man page)¶
remote_name
isorigin
by default. To simply callgit push
, set up the default remote once by runninggit push -u remote_name branch_name
Remove a file from staging (man page)¶
Restore file to last committed version (undo current modifications) (man page)¶
Undo a commit ⚠️ (man page)¶
Be careful with this command. If you pushed the commit to the remote already, you will have to force a push as commit hashes will be different.
Must know commands¶
Status of changes (man page)¶
Use this all the time to know what changed in your tree.
Show previous commits (man page)¶
git log --oneline --decorate --graph
to get a nice readable log
Switch braches (man page)¶
git branch -b new_branch
will createnew_branch
and switch to it.