(Usage hints for this presentation)
Summer Term 2023
Dr. Jens Lechtenbörger (License Information)
How to collaborate on shared documents as distributed team?
Who changed what why when?
Git-Intro-Final-1.1.txt or
Git-Intro-Final-reviewed-Alice.txt
Reference: Pro Git book

“Git Logo” by Jason Long under CC BY 3.0; from git-scm.com
Fork/clone repository: Create copy of repository
Commit (aka check-in)
Branches
“Git Branches” by Atlassian under CC BY 2.5 Australia; dimension attributes added, from Atlassian
Prepare answers to the following questions
git init in any directory
main or master
clone
git clone https://gitlab.com/oer/cs/programming.git
cd programming
git push, which you are not
allowed here)git pull merges changes to bring your copy up to dategit clone https://gitlab.com/oer/cs/programming.gitprogramming
.git (with Git meta-data)git status
Git-Introduction.orgtest.txtgit status again
Git-Introduction.org as not staged and modifiedtest.txt as untrackedgit add to stage for commitgit checkout to discard changesstaged before commit
git add is used for that purposegit add Git-Introduction.orggit status
Git-Introduction.org as to be committed
and modifiedGit-Introduction.org moregit status
Git-Introduction.org as
git diff
git diff --cached
git add Git-Introduction.orgdiff variants again
git help diffgit commands is availablegit commit -m "<what was improved>"
<what was improved> should be meaningful textgit status
Git-Introduction.org
git push
suggested for follow-upgit log (press h for help, q to quit)
git reset HEAD~
git status and git log
git add with git reset
git add Git-Introduction.orggit reset Git-Introduction.orggit checkout -- <file>git stash
git checkout ... on previous slide,
change some file firstgit status and find yourself on previous commitgit pullgit stash apply
git checkout -b testbranch
-b: Create new branch and switch to it
git status and find yourself on new branch
main (or master)maingit checkout main and git checkout testbranch to
switch branches
git know
git switch for
the same purpose)git remote -v
git clone is called origingit initupstream remote
(see next two slides)push (requires permission)
push to your own projectsorigin:
git push -u origin testbranchupstream
(section in Pro Git)
master branch based on upstream’s master branchupstream:
git remote add upstream <HTTPS-URL of source project>upstream: git fetch upstreamupstream/master into your master, maybe with
rebase:
git checkout mastergit rebase upstream/mastergit pushgit status
inspects repository, in particular file states
untracked, if they are located
inside a Git repository but not managed by Gittrackedtracked files, which states can you identify from
the demo? Which commands are presented to perform what state
transitions?merge and rebase both unify two branchesfeature and committed on that
branch; in the meantime, somebody else committed to master
“A forked commit history” by Atlassian under CC BY 2.5 Australia; from Atlassian
“Merging” by Atlassian under CC BY 2.5 Australia; from Atlassian
feature branch on master
feature on masterfeature)
merge for remote branches
“Rebasing” by Atlassian under CC BY 2.5 Australia; from Atlassian
git clone <project-URI> # Then, later on retrieve latest changes: git fetch origin # See what to do, maybe pull when suggested in status output: git status git pull # Create new branch for your work and switch to it: git checkout -b nameForBranch # Modify/add files, commit (potentially often): git add newFile git commit -m "Describe change" # Push branch: git push -u origin nameForBranch # Ultimately, merge or rebase branch nameForBranch into branch master git checkout master git merge nameForBranch # If conflict, resolve as instructed by git, commit. Finally push: git push
README.md in Markdown syntaxThis document is part of an OER collection to teach basics of distributed systems. Source code and source files are available on GitLab under free licenses.
Except where otherwise noted, the work “Git Introduction”, © 2018-2023 Jens Lechtenbörger, is published under the Creative Commons license CC BY-SA 4.0.