(Usage hints for this presentation)
VM OER 2020/2021
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
master
branch
master
is not more special than any other branch you may createclone
git clone https://gitlab.com/oer/cs/programming.git
git pull
merges changes to bring your copy up to dategit clone https://gitlab.com/oer/cs/programming.git
programming
.git
(with Git meta-data)git status
master
) and potential changesGit-Introduction.org
test.txt
git 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.org
git 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.org
diff
variants again
git help diff
git
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.org
git reset Git-Introduction.org
git checkout -- <file>
git stash
git checkout ...
on previous slide,
change some file firstgit status
and find yourself on previous commitgit pull
git stash apply
git checkout -b testbranch
-b
: Create new branch and switch to itgit status
and find yourself on new branch
master
master
git checkout master
and git checkout testbranch
to
switch branchesgit remote -v
git clone
is called origin
git init
upstream
remote
(see next two slides)push
(requires permission)
push
to your own projectsorigin
:
git push -u origin testbranch
upstream
(section in Pro Git)
origin
origin
master
master
branch based on upstream’s master
branchupstream
:
git remote add upstream <HTTPS-URL of source project>
upstream
:
git fetch upstream
master
into your master
, maybe with
rebase:
git checkout master
git rebase upstream/master
git push
git status
inspects repository, in particular file states
untracked
, if they are located
inside a Git repository but not managed by Gittracked
tracked
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 master
“Rebasing” by Atlassian under CC BY 2.5 Australia; from Atlassian
master
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 a larger course. Source code and source files are available on GitLab under free licenses.
Except where otherwise noted, the work “Git Introduction”, © 2018-2020 Jens Lechtenbörger, is published under the Creative Commons license CC BY-SA 4.0.