This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ===== GIT ===== ==== Overview ==== === What is it? === * Distributed VCS * Manages workflows of over [[https://www.linuxfoundation.org/wp-content/uploads/2020/08/2020_kernel_history_report_082620v2.pdf|10 commits per hour]] * Works best with textual content or source code * Ability to create/edit locally with tools you know * Self contained history and configuration in ''%%.git%%'' folder * Only up-/download need network ==== How does it work? ==== * Similar to ''%%diff%%'' and ''%%patch%%'' utilities * Stores history in a compressed hash-based store * Current checkout is the regular directory structure * Saves meta information with every commit for traceability ===== GIT Commands ===== ==== Get a repository ==== === Create a new one === <code> cd <REPO> git init ls -alh </code> === Clone an existing one === <code> git clone https://github.com/<USER>/<REPO> cd <REPO> ls -alh </code> ==== Check the state it’s in ==== <code> git status git diff git diff --cached git log </code> Note: this may use the pager (''%%less%%''/''%%more%%'') ==== Get changes from others ==== Get changes from a specific remote, optionally integrating them into the current branch <code> git fetch <REMOTE> git pull <REMOTE> </code> You can always fetch the changes but pulling requires the local and remote branches to be somewhat aligned. * Pulling should be a ''%%fast-forward%%'' operation. * The current branch is a direct ancestor of the remote branch. * Ensures that pushing to the remote won’t introduce unrelated changes. ==== Push changes ==== <code> git push <REMOTE> <BRANCH> </code> ^Github/Gitlab ^Regular Git ^ |Changes are pushed to your account |changes are pushed to a throw-away branch| |Merged by using a PR/MR on the website|Merged manually if no conflicts arise | |Inspection by collaborators during MR |No inspection until deployed | > Do **NOT** push directly to ''%%master%%''! ==== Mistakes and Corrections ==== From safe to loosing all local changes since last commit: <code> git stash git reset git reset --hard git checkout <CLEAN> && git checkout -B <BRANCH> </code> **Read the [[git-scm.com|manual]] before loosing more of your changes than you wanted to reset!** ===== Workflow ===== ==== Workflow 1 ==== Highly dependent on project/organization! But: * use branches, don’t work directly on ''%%master%%'' * try to work on one topic at a time * switch between branches when working on different parts of the project * create ''%%merge request%%''s for every branch, that’s done or ready for review * write consice ''%%commit message%%''s ==== Workflow 2 ==== Combined like this is a good way to start working: * Start by syncing the progress of upstream <code bash> git checkout master git pull origin git checkout -b addGitTalk </code> * Work on your changes to the project * Add new code followed by <code bash> git diff git status git add [PATH] git diff --cached </code> * Repeat the two previous step or publish <code bash> git commit git push </code></blockquote></HTML> ==== Work on a feature ==== - Create a new branch, which starts out identical to the current - Work on the project - Mark your changes as ready - Check if all the changes look good and are marked for inclusion in the next commit - Add your changes to the branch inside the repository <code bash> git checkout -b <NAME> ... git add [PATH] git diff; git diff --cached git commit </code> pandoc/git/01_general/git.txt Last modified: 2020/10/20 08:09by pandoc