{no densequote} ## Git {libyli} -SVN → Git migration in progress. 8h to retrieve full SVN history,
less than 1min to push full history to Git (same network)!
{densequote} - History of Git - open source - initiated by Linus Torvalds - first release: 7 April 2005 - version 2.11.0 on the 29th November 2016 - fast and efficient - most used version control system # @copy:#plan: %+class:inred: .git ## Setting up / Customizing Git {#introduceyourself libyli} - Introducing yourself (MANDATORY)Git (/ɡɪt/) is a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for software development, but it can be used to keep track of changes in any files.
wikipedia
As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows. Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development…
git config --global user.name "John Doe"- these are used to “sign” your changes - the email is not used to send email and can be fake - Choose your editor
git config --global user.email john@doe.com
git config --global core.editor "emacs"- The global configuration is in **~/.gitconfig** - Software Carpentry help about configuring git - http://swcarpentry.github.io/git-novice/02-setup/ - Fancy colors and shortcuts
git config --global color.ui true## Setting up git *{action}* *{demo}* {no-print}
git config --global alias.st status
git config --global alias.ci commit
git config --global user.name "John Doe"- To choose emacs as editor
git config --global user.email john@doe.com
git config --global core.editor "emacs"- To choose nano as editor
git config --global core.editor "nano -w"- To choose atom as editor
git config --global core.editor "atom --wait" {dense}- Trapped in an editor? - save and quit "vi" by typing `:wq` Enter - save and quit "nano" with Ctrl+O Enter Ctrl+X - save and quit "emacs" with Ctrl+X Ctrl+S Ctrl+X Ctrl+C ## Starting with Git {libyli} - Initializing your repository/project (the current directory)
git init- What's up? (this does not modify anything)
git status- Deciding what is relevant
git add file1 file2 …@SVG: swc-media/git-staging-area.svg 800 230 {slide unpad} ## Adding and changing some files *{demo}* // script "simple.txt"
git commit
cp -r base mypaper ; cd mypaper git init git status git add mypaper.tex cvpr.sty git status git commit git status ... and more… - (diagram) {denser} ## Creating a repository *{action}* - Create a folder `recipes` - Change the current directory (go inside `recipes`) - Init your repository - Run `ls -a`, what does it list? - (draw your diagram) {dense} ## Adding and changing a file *{action}* - Create a `salad.md` file and type a recipe in it - See what `git status` gives - Add your file and check `git status` again - Commit your file, and check `git status` again - Modify your recipe and commit your changes, … repeat - (draw your diagram) {dense} - Recap - beginning
git init- working
git add ...
git commit [-m ...]
git status## Finer inspection and control over changes {libyli} - Keep your project clean: ignoring files - **.gitignore** file(s) - patterns - **blabla.* ** (ignore files starting with `blabla`) - **!blabla.my_precious** (but not `blabla.my_precious`) - **/build/** (ignore the `build` folder) - **build/** (ignore all `build` folders (at any level)) - ***~** (ignore files ending with `~`) - What did I just modify?
git add ...
git commit [-m ...]
git status- What happened?
git diff [...]
git log## Adding and changing a file *{action}* - Create a `tmp.log` file with some useless content in it - Create a `all.log` file with some useless content in it - Check `git status` - Create a `.gitignore` with one line containing `tmp.log` - Check `git status` - Commit the `.gitignore` file - Check `git status` # @copy:#plan: %+class:inred: .githisto ## Exploring the History {libyli} - Remember **git log**? - Each commit is written in stone - parent(s) commit - author - modifications - sha1sum (e.g. cb6dc3cb1f4f5eb15c1d9b2b25ae741cd73c0554)
git diff cb6dc3...- Can be use to retreive a file
git checkout cb6dc3... -- thefile.ext- … get commit IDs, diff, checkout *{demo}* ## Exploring history *{action}* - Find the SHA1 of a previous version (your choice) - Diff with an old version of your recipe - Recover an old version - Recover the latest version - NB: call for help in case of “detached HEAD” - run `git checkout master` # Good Files and Good Commits
git config --global core.excludesfile /pathto/yourfile{no} ## What is a good commit? {libyli} - You're writing history! do it well! - Use conventional commit messages {libyli} - first line is the short message (50 character) - the rest is separated from the short message by an empty line - be consistent on the short message format, e.g. - start with a capital letter - do not put a `.` at the end - recommended reading on commit messages - Use meaningful commit messages, e.g. {libyli} - `Changes{dense}` (bad, unspecific) - `Add line "if attr is None: return False"{dense}` (bad, redundant) - `Handling problem with unset attributes{dense}` (ok, ✓) - Using meaningful content - don't make huge commits with unrelated changes - split changes in as many "independent" commits as needed ## Tips and Tricks (better and lost commits) {libyli} - Fine-grained selection of the parts to add - use the interactive `git add -p yourfile.ext` - Fix the previous commit - make the changes (corrections) - use `git commit --amend` - can change the message too `git commit --amend -m '.....'` - ok *{demo}* # @copy:#plan: %+class:inred: .multigit ## Back to the Future: parallel universes *{demo}*
git log git checkout 41474a33e098689b... emacs paper.tex git commit git log git log --graph --oneline --all --color git checkout -b mytest # Get a nice summary git log --graph --oneline --all --decorate # GUI gitk gitk --all## Branches: recap {libyli} - The many faces of `git checkout` 😓😞😢 - moving in the history
git checkout sha1-or-branch-name{denser} - creating a new branch at current position
git checkout -b new-branch-name{denser} - getting a file from the history
git checkout sha1-or-branch-name -- filename.ext{denser} - Branch - a label for a commit - automatically follows on new commit (**git commit**) - `master` is a branch created by `git init` (by convention) - `HEAD` is a reference to the last checked out revision - Use of “sha1” or branch-name (e.g. brrrr) - Shortcuts (about ^ and ~)
cb6dc3, brrrr, HEAD,## Parallel universes and branches *{action}* - Use `git log` to find the SHA1 of a previous commit - Use `git diff` to compare your version with this one - Use `git checkout yourSha1` to get this version - Check that the files have changed - Use `git checkout -b magic` to create a new branch there - Make new commit(s) - Check the history - Use `git checkout master` to switch back to "master" - Check the history and current version
HEAD^, HEAD~, HEAD~~, HEAD~2, HEAD~42,
HEAD^2, cb6dc3^42, tagggg
git merge 41474a33- Possible situations {slide libyli} - already the same version (or 41474a33… is an ancestor) - → nothing {no} - the current version is an ancestor (older) - → “fast-forward” merge {no} - versions have diverged - → full merge {no} - conflicts only if the same file has been modified at the same place - Merging branch `brrrr` into master *{demo}*
git checkout master{slide} ## Merging: recap - Always commit before merging - commit is cheap, easy and local - you never loose anything when merging // maybe your temper - Non-conflicting **git merge** ⇒ automatic commit - Conflicting **git merge** - (partial merge) - non-conflicting changes are automatically added - you: solve conflict - you: `git add` - you: `git commit`
git merge brrrr
{no densequote} ## Let's Go - Create a repository on GitLab - Push our content - link our repository to the remote repository (on GitLab) - push the changes to this remote repository - On another machine - clone the repository - make changes, commit and push them - On this machine - pull changes: fetch them and then merge ## Recap GitLab (and Git remotes) {libyli} - GitLab project == git repository (+ wiki etc) - The local repository can be linked to some remote one(s) - When we `git clone`, a remote named `origin` is set up - When we `git fetch`, we download the remote changes - ... we can then use `git merge` to integrate them - ... or `git pull` that does fetch+merge - When we `git push`, we upload our history of changes to the remote - Reminder: always commit before merge or pull ## More GitLab (additions to git) {libyli} - Groups - groups of users (e.g., PhD student and supervisors) - automatic access to the projects of the group - Forking - take a repository on GitLab - make a “personal” copy of this repository (still on GitLab) - Merge requests (pull requests in GitHub) - ask for another repo to integrate changes from your fork - Issues - bug - questions - feature requests - Wikis - set of pages, in markdown - (also accessible as a git repository) # @copy:#plan: %+class:inred: .workflows ## Git workflow: repositories and branches - Shared central repository (for small tight groups) - one repository on gitlab - all collaborators have read/write access - a "master" branch, with possible additional branch - Set of personal "central" repositories - one "fork" on gitlab for each collaborator - the fork acts as the collaborator's branch - merging into the "principal" repository via "merge requests" (or pull requests) - Fully distributed (rarely used today) - repositories on collaborators machines - **fetch** from one another ## Git workflow: merging versus rebase {libyli} - Merging - `git merge` - keeps explicit information about parallel work - creates ugly history with several active collaborators - Rebasing - `git rebase` - replays the diverging commits on top of latest ones - creates a more linear history - warning: rewrites history - Recommendation - start with merging - when you get annoyed by the shape of the history - if you're used to merge/push/pull - then start using `git rebase -i origin/master` - *{demo}* *{action}* ## Advantages and dangers ofGitLab offers git repository management, code reviews, issue tracking, activity feeds, wikis.
/ − will be replaced by the title
−