Questions
analyses.R
is the final one?data.csv
?Questions
analyses.R
is the final one?data.csv
?We need a tool that deals with versions for us
git
git
is a Version Control System (VCS).
git
git
is a Version Control System (VCS). With git
you can:
git
and GitHub
are not the same thing
git
is a free and open-source softwareGitHub
(and co) is a web platform to host and share projects tracked by git
In other words:
You do not need
GitHub
to usegit
but you cannot useGitHub
without usinggit
Git main panel
Stage files, view differences and commit changes
View history and versions
git
git
work?git
takes a sequence of snapshots!=
file hosting services like Dropbox, Google Drive, etc.) In the git
universe, a snapshot is a version, i.e. the state of the whole project at a specific point in time
A snapshot is a two-step process:
commit message
) Initialize git
in a (empty) folder (repository
)
Add new files in the repository
Stage
(select) one file
Stage
(select) several files
Stage
(select) all files
Commit
changes to create a new version
Now we are up-to-date
With git
a file can be untracked or tracked1. If it’s tracked, it can be:
When you create a new file, by default it’s untracked.
To tell git
to track this new file, you have to stage it.
After commiting your changes, the file becomes unmodified (up-to-date with the latest version).
If you edit tracked file, it becomes modified.
When you decide to create a new version, stage the modified file.
After commiting your changes, the file becomes unmodified (up-to-date with the latest version).
.gitignore
We can also tell git
to ignore specific files: it’s the purpose of the .gitignore
file
Which files? For instance:
.gitignore
We can also tell git
to ignore specific files: it’s the purpose of the .gitignore
file
Which files? For instance:
Template for projects available here
When committing a new version (w/ git commit
), the following information must be added:
WHO
- the person who has made the changes git
)WHEN
- the date of the commit git
)WHAT
- the files that have been modified git add
)WHY
- the reason of the commit, i.e. what has been done compared to the previous version git commit
)When committing a new version (w/ git commit
), the following information must be added:
WHO
- the person who has made the changes git
)WHEN
- the date of the commit git
)WHAT
- the files that have been modified git add
)WHY
- the reason of the commit, i.e. what has been done compared to the previous version git commit
)An optional body can be added to provide detailed information and to link external references (e.g. issue, pull request, etc.)
GitHub and co are cloud-based git repository hosting services
Perfect solutions to collaborate on projects tracked by git
Services
Overview
Advantages
git
Add a new file: README.md
Stage
changes
Commit
changes
Push
changes to remote
Pull
changes from remote
Pull
changes from remote
When you try to push, you might see this following error message:
git push
# To github.com:ahasverus/projectname.git
# ! [rejected] main -> main (fetch first)
#
# error: failed to push some refs to 'github.com:ahasverus/projectname.git'
#
# hint: Updates were rejected because the remote contains work that you do
# hint: not have locally. This is usually caused by another repository pushing
# hint: to the same ref. You may want to first integrate the remote changes
# hint: (e.g., 'git pull ...') before pushing again.
# hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Just git pull
and try to git push
again
When you try to pull, you might see this following error message:
git pull
# [...]
# Auto-merging README.md
# CONFLICT (content): Merge conflict in README.md
#
# error: could not apply b8302e6... edit README
#
# hint: Resolve all conflicts manually, mark them as resolved with
# hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
# hint: You can instead skip this commit: run "git rebase --skip".
# hint: To abort and get back to the state before "git rebase",
# hint: run "git rebase --abort".
Welcome to the wonderful world of git
conflicts
What is a (lexical) conflict?
A git
conflict appears when two versions cannot be merged by git
because changes have been made to the same lines.
You have to decide which version you want to keep.
What is a (lexical) conflict?
A git
conflict appears when two versions cannot be merged by git
because changes have been made to the same lines.
README.md
- Version A
Git
will identify conflicts in files:
You have to decide which version you want to keep.