class: title-slide count: false .title[ # 07 - Git ] .subtitle[ ## Open Science Tools ] .author[ ### Claudio Zandonella & Davide Massidda ] .institute[ ] --- class: center, middle, inverse # Step VI: Versioning --- # Versioning -- .pull-left-50[ <br> - Keep everything in order - Collaborating ] .pull-right-50[ .move-up-70[ {{content}} ] ] -- <img src="images/07-git/final-doc.jpeg" width="85%" style="display: block; margin: auto;" /> --- # Versioning .pull-left-50[ <br> - Keep everything in order - Collaborating <br> .center[ ### No problem, there is a solution ] <img src="images/07-git/git-logo.png" width="30%" style="display: block; margin: auto;" /> ] .pull-right-50[ .move-up-70[ <img src="images/07-git/final-doc.jpeg" width="85%" style="display: block; margin: auto;" /> ] ] --- # Git Nice Fact 🐧 -- .pull-left-50[ <div style = 'margin-top: -10pt;'> <img src="images/07-git/linus.jpeg" width="60%" style="display: block; margin: auto;" /> </div> ] .pull-right-50[ {{content}} ] --- # Git Nice Fact 🐧 .pull-left-50[ <img src="images/07-git/linus.png" width="80%" style="display: block; margin: auto;" /> ] .pull-right-50[ {{content}} ] -- <img src="images/07-git/linux-logo.png" width="70%" style="display: block; margin: auto;" /> <br> <img src="images/07-git/git-logo.png" width="70%" style="display: block; margin: auto;" /> --- # Git Concepts -- .pull-left-30[ <br> - Tracking files - Managing collaboration - Branching ] .pull-right-70[ ] --- # Git Concepts .pull-left-30[ <br> - Tracking files - .alpha[Managing collaboration] - .alpha[Branching] ] .pull-right-70[ .move-down-80[ .li-small[ - Track all changes to files - Detailed history and traceability - Check earlier versions - Restore previous version ] ] ] --- # Git Concepts .pull-left-30[ <br> - Tracking files - .alpha[Managing collaboration] - .alpha[Branching] ] .pull-right-70[ <img src="images/07-git/local-work-1.png" width="100%" style="display: block; margin: auto;" /> .width-30[ {{content}} ] ] -- ``` - my-project/ |-.git/ |- data/ |- analysis/ |- code/ |- README ``` --- # Git Concepts .pull-left-30[ <br> - Tracking files - .alpha[Managing collaboration] - .alpha[Branching] ] .pull-right-70[ <img src="images/07-git/local-work-1.png" width="100%" style="display: block; margin: auto;" /> .width-30[ ``` - my-project/ * |-.git/ |- data/ |- analysis/ |- code/ |- README ``` ] ] --- # Git Concepts .pull-left-30[ <br> - Tracking files - .alpha[Managing collaboration] - .alpha[Branching] ] .pull-right-70[ .move-up-70[ <img src="images/07-git/history.png" width="100%" style="display: block; margin: auto;" /> ] <br> .li-small[ {{content}} ] ] -- - Commits are identified by unique `SHA-1 hash ID` - `master` (or `main`) default branch - It is a *pointer* (reference) to a commit - `HEAD` the current commit we are viewing --- # Git Concepts .pull-left-30[ <br> - Tracking files - .alpha[Managing collaboration] - .alpha[Branching] ] .pull-right-70[ .move-up-70[ <img src="images/07-git/history.png" width="100%" style="display: block; margin: auto;" /> .center[`checkout`] <img src="images/07-git/checkout.png" width="100%" style="display: block; margin: auto;" /> ] <br> .center[ {{content}} ] ] -- ### We have a time machine! --- # Git Concepts .pull-left-30[ <br> - Tracking files - .alpha[Managing collaboration] - .alpha[Branching] ] .pull-right-70[ <img src="images/07-git/local-work-2.png" width="100%" style="display: block; margin: auto;" /> ] --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - Managing collaboration - .alpha[Branching] ] .pull-right-70[ <br> .move-down-80[ .li-small[ {{content}} ] ] ] -- - Multiple colleagues - Work independently - Avoiding conflicts --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - Managing collaboration - .alpha[Branching] ] .pull-right-70[ .move-up-70[ <img src="images/07-git/collaborate.png" width="90%" style="display: block; margin: auto;" /> ] <br> .move-up-15[ .li-small[ {{content}} ] ] ] -- - Always pull first - Solve conflicts --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - Managing collaboration - .alpha[Branching] ] .pull-right-70[ <img src="images/07-git/workflow.png" width="100%" style="display: block; margin: auto;" /> ] --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - .alpha[Managing collaboration] - Branching ] .pull-right-70[ .move-down-170[ .li-small[ {{content}} ] ] ] -- <br> - Create different branches - Allow us to make changes independently - Integrate all changes --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - .alpha[Managing collaboration] - Branching ] .pull-right-70[ <img src="images/07-git/branch.png" width="100%" style="display: block; margin: auto;" /> ] --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - .alpha[Managing collaboration] - Branching ] .pull-right-70[ .move-down-30[ #### Branching <img src="images/07-git/merge-extra-1.png" width="100%" style="display: block; margin: auto;" /> ] ] --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - .alpha[Managing collaboration] - Branching ] .pull-right-70[ .move-down-30[ #### Merging <img src="images/07-git/merge-extra-2.png" width="100%" style="display: block; margin: auto;" /> .move-down-60[ .li-small[ {{content}} ] ] ] ] -- #### Extra: Merging Mechanism - Obtain a *“merge commit”* - Branches still exist and are independent --- # Git Concepts .pull-left-30[ <br> - .alpha[Tracking files] - .alpha[Managing collaboration] - Branching ] .pull-right-70[ <img src="images/07-git/workflow-adv-2.png" width="100%" style="display: block; margin: auto;" /> ] --- class: inverse, center, middle # Getting Started --- # Getting Started: Configure Settings -- .pull-left-50[ Add username and email .code-size-12[ ```bash $ git config --global user.name "<My Name>" $ git config --global user.email "<user@email.com>" ``` ] ] .pull-right-50[] --- # Getting Started: Configure Settings .pull-left-50[ Add username and email .code-size-12[ ```bash $ git config --global user.name "<My Name>" $ git config --global user.email "<user@email.com>" ``` ] Configuration file .code-size-12[ ```bash #---- ~/.gitconfig ----# [user] name = My Name email = user@email.com ``` ] ] .pull-right-50[] --- # Getting Started: Configure Settings .pull-left-50[ Add username and email .code-size-12[ ```bash $ git config --global user.name "<My Name>" $ git config --global user.email "<user@email.com>" ``` ] Configuration file .code-size-12[ ```bash #---- ~/.gitconfig ----# [user] name = My Name email = user@email.com ``` ] ] .pull-right-50[ Current settings .code-size-12[ ```bash $ git config --list ``` ] ] --- # Getting Started: Configure Settings .pull-left-50[ Add username and email .code-size-12[ ```bash $ git config --global user.name "<My Name>" $ git config --global user.email "<user@email.com>" ``` ] Configuration file .code-size-12[ ```bash #---- ~/.gitconfig ----# [user] name = My Name email = user@email.com ``` ] ] .pull-right-50[ Current settings .code-size-12[ ```bash $ git config --list ``` ] .move-down-40[ Settings levels ] .li-small[ - `--system` system level<br>Stored in `/etc/gitconfig` - `--global` user level<br>Stored in `~/.gitconfig` - No flag, project level<br>Stored in `.git/config` ] ] --- # Getting Started: Initialize Repository -- .pull-left-50[ - Already existing directory .code-size-12[ ```bash $ cd <path-to/project-directory> $ git init ``` ] {{content}} ] .pull-right-50[] -- > Create an hidden folder `.git/` --- # Getting Started: Initialize Repository .pull-left-50[ - Already existing directory .code-size-12[ ```bash $ cd <path-to/project-directory> $ git init ``` ] > Create an hidden folder `.git/` - Get remote repository .code-size-12[ ```bash $ git clone <repository-URL> ``` ] ] .pull-right-50[ ] --- # Getting Started: Tracking Files -- .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[] ] .pull-right-60[ .move-up-30[ .code-size-12[ {{content}} ] ] ] -- ``` my-project/ |-- README |-- data/ | |-- raw-data.csv |-- documents/ |-- code/ | |-- my-functions-1 | |-- my-functions-2 ``` --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ``` my-project/ |-- README |-- data/ | |-- raw-data.csv |-- documents/ |-- code/ | |-- my-functions-1 | |-- my-functions-2 ``` ```bash $ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) code/ data/ README nothing added to commit but untracked files present (use "git add" to track) ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ``` my-project/ |-- README |-- data/ | |-- raw-data.csv * |-- documents/ |-- code/ | |-- my-functions-1 | |-- my-functions-2 ``` ```bash $ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) * code/ * data/ * README nothing added to commit but untracked files present (use "git add" to track) ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ``` my-project/ |-- README |-- data/ | |-- raw-data.csv * |-- documents/ |-- code/ | |-- my-functions-1 | |-- my-functions-2 ``` ] ] <br> #### Extra: `.git-track` Git do not track empty directories<br>Create and hidden empty file to track them .code-size-12[ ```bash $ touch <path-to-empty-dir>/.git-track ``` ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state - `git add <file>`<br>Add file to stage area ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ``` my-project/ |-- README |-- data/ | |-- raw-data.csv |-- documents/ |-- code/ | |-- my-functions-1 | |-- my-functions-2 ``` ```bash $ git add README <other-files> ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state - `git add <file>`<br>Add file to stage area - `--all` add files ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ``` my-project/ |-- README |-- data/ | |-- raw-data.csv |-- documents/ |-- code/ | |-- my-functions-1 | |-- my-functions-2 ``` ```bash $ git add README <other-files> ``` ```bash $ git add --all $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: code/my-functions-1 new file: code/my-functions-2 new file: data/raw-data.csv new file: README ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state - `git add <file>`<br>Add file to stage area - `--all` add files - `git rm --cached <file>`<br>Remove file from staging area - `git reset`<br>Remove all files from staging area ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ``` my-project/ |-- README |-- data/ | |-- raw-data.csv |-- documents/ |-- code/ | |-- my-functions-1 | |-- my-functions-2 ``` ```bash $ git rm --cached data/raw-data.csv ``` {{content}} ] ] ] -- ```bash $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: code/my-functions-1 new file: code/my-functions-2 new file: README Untracked files: (use "git add <file>..." to include in what will be committed) data/ ``` --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state - `git add <file>`<br>Add file to stage area - `--all` add files - `git rm --cached <file>`<br>Remove file from staging area - `git reset`<br>Remove all files from staging area ] ] .pull-right-60[ .move-down-30[ #### Extra: `.gitignore` ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Adding Files ] .li-small[ - `git status`<br>Check the project state - `git add <file>`<br>Add file to stage area - `--all` add files - `git rm --cached <file>`<br>Remove file from staging area - `git reset`<br>Remove all files from staging area ] ] .pull-right-60[ .move-down-30[ #### Extra: `.gitignore` ] Matching patterns rules: .li-small[ - `note.txt` file name (in any directory) - `folder-A/note.txt` path specification - `folder-A/` directory name (in any directory) - `*.log` file extension - `folder-A/*.log` path specification - `!important.log` create exceptions ] {{content}} ] -- Patterns according to `.gitignore` position --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Committing Changes ] .li-small[ - `git commit`<br>Create a commit ] ] .pull-right-60[ .code-size-12[ .move-down-80[ {{content}} ] ] ] -- ```bash $ git commit ``` --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Committing Changes ] .li-small[ - `git commit`<br>Create a commit ] ] .pull-right-60[ .move-down-80[ .code-size-12[ ```bash $ git commit ``` ```bash #---- commit messagge ----- Init Repo - add code scripts - add README ``` ] ] .move-down-30[ .li-small[ {{content}} ] ] ] -- Commit Messages: - Brief title (< 50 characters) - List of main changes - Explain **why** --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Committing Changes ] .li-small[ - `git commit`<br>Create a commit - `-a` all changes to tracked files - `-m <text>` commit message ] ] .pull-right-60[ .move-down-80[ .code-size-12[ ```bash $ git commit ``` ```bash #---- commit messagge ----- Init Repo - add code scripts - add README ``` ```bash $ git commit -am "Update README" ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Committing Changes ] .li-small[ - `git commit`<br>Create a commit - `-a` all changes to tracked files - `-m <text>` commit message - `git log` See history - `--oneline` compact version ] ] .pull-right-60[ .move-down-80[ .code-size-12[ ```bash $ git log commit ec15cb085c2e5aa463778bbef3239b06b9ac4010 (HEAD -> master) Author: username <user@email.com> Date: Tue Feb 15 10:06:27 2022 +0100 Update README commit 93398d18e686d4698af3e52a0677585afe467a19 Author: username <user@email.com> Date: Tue Feb 15 09:26:13 2022 +0100 Init Repo - add code scripts - add README ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Committing Changes ] .li-small[ - `git commit`<br>Create a commit - `-a` all changes to tracked files - `-m <text>` commit message - `git log` See history - `--oneline` compact version - `git diff`<br>See changes since last commit ] ] .pull-right-60[ .code-size-12[ .move-down-80[ ```bash $ git diff diff --git a/README b/README index 64772c2..e994379 100644 --- a/README +++ b/README @@ -1 +1,2 @@ This is my first project using Git! +New information ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-30[ #### Committing Changes ] .li-small[ - `git commit`<br>Create a commit - `-a` all changes to tracked files - `-m <text>` commit message - `git log` See history - `--oneline` compact version - `git diff`<br>See changes since last commit - `<commit-ID>`<br>Since specified commit - `<commit-A> <commit-B>`<br>From commit-A to commit-B ] ] .pull-right-60[ .code-size-12[ .move-down-80[ ```bash $ git diff diff --git a/README b/README index 64772c2..e994379 100644 --- a/README +++ b/README @@ -1 +1,2 @@ This is my first project using Git! +New information ``` ] ] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[] ] .pull-right-60[ {{content}} ] -- <img src="images/07-git/history.png" width="90%" style="display: block; margin: auto;" /> --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit ] ] .pull-right-60[ <img src="images/07-git/history.png" width="90%" style="display: block; margin: auto;" /> .code-size-12[ ```bash $ git checkout 60e117d7 ``` ] {{content}} ] -- <img src="images/07-git/checkout.png" width="90%" style="display: block; margin: auto;" /> --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit ] ] .pull-right-60[ <img src="images/07-git/history.png" width="90%" style="display: block; margin: auto;" /> .code-size-12[ ```bash $ git checkout 60e117d7 ``` ] <img src="images/07-git/checkout.png" width="90%" style="display: block; margin: auto;" /> .center[*Warning! Detached* `HEAD`] ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit ] ] .pull-right-60[ .move-up-30[ In detached `HEAD`, changes will be lost! ] <img src="images/07-git/checkout.png" width="90%" style="display: block; margin: auto;" /> ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit ] ] .pull-right-60[ .move-up-30[ In detached `HEAD`, changes will be lost! ] <img src="images/07-git/checkout.png" width="90%" style="display: block; margin: auto;" /> .code-size-12[ ```bash $ git checkout -b new-branch ``` ] {{content}} ] -- <img src="images/07-git/checkout-diverge.png" width="90%" style="display: block; margin: auto;" /> --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit ] ] .pull-right-60[ <img src="images/07-git/history.png" width="90%" style="display: block; margin: auto;" /> ] --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit - `git revert <commit-ID>`<br>Undo commits (keep track) ] ] .pull-right-60[ <img src="images/07-git/history.png" width="90%" style="display: block; margin: auto;" /> .code-size-12[ ```bash $ git revert 7bf97593 $ git revert 9d109cfe ``` ] {{content}} ] -- <img src="images/07-git/revert.png" width="95%" style="display: block; margin: auto;" /> --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit - `git revert <commit-ID>`<br>Undo commits (keep track) - `git reset <commit-ID>`<br>Undo commits (delete) ] ] .pull-right-60[ <img src="images/07-git/history.png" width="90%" style="display: block; margin: auto;" /> .code-size-12[ ```bash $ git revert 7bf97593 $ git revert 9d109cfe ``` ] {{content}} ] -- <img src="images/07-git/reset.png" width="90%" style="display: block; margin: auto;" /> --- # Getting Started: Tracking Files .pull-left-40[ .move-down-80[ #### Undoing Commits ] .li-small[ - `git checkout <commit-ID>`<br>Point `HEAD` to commit - `git revert <commit-ID>`<br>Undo commits (keep track) - `git reset <commit-ID>`<br>Undo commits (delete) {{content}} ] ] .pull-right-60[ <img src="images/07-git/history.png" width="90%" style="display: block; margin: auto;" /> .code-size-12[ ```bash $ git revert 7bf97593 $ git revert 9d109cfe ``` ] <img src="images/07-git/reset.png" width="90%" style="display: block; margin: auto;" /> .center[All changes are maintained in the files] ] -- - `--hard` to discard changes<br>(or `git restore <file>`) --- # Getting Started: Collaboration -- .pull-left-40[ .move-down-40[ #### ] .li-small[ - `git remote add <name> <url>`<br>Add remote repository ] ] .pull-right-60[ .move-down-90[ .code-size-12[ ```bash $ git remote add origin https://github.com/username/my-project.git ``` ] ] {{content}} ] -- > `origin` no special meaning per se! --- # Getting Started: Collaboration .pull-left-40[ .move-down-40[ #### ] .li-small[ - `git remote add <name> <url>`<br>Add remote repository - `git remote -v`<br>List remote repository ] ] .pull-right-60[ .move-down-90[ .code-size-12[ ```bash $ git remote add origin https://github.com/username/my-project.git ``` ] ] > `origin` no special meaning per se! .code-size-12[ ```bash $ git remote -v origin https://github.com/username/my-project.git (fetch) origin https://github.com/username/my-project.git (push) ``` ] ] --- # Getting Started: Collaboration .pull-left-40[ .move-down-40[ #### ] .li-small[ - `git remote add <name> <url>`<br>Add remote repository - `git remote -v`<br>List remote repository - `git pull <remote> <branch>`<br>Download commits from remote ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ```bash $ git pull origin master ``` ] ] {{content}} ] -- <img src="images/07-git/pull.png" width="75%" style="display: block; margin: auto;" /> {{content}} -- > `pull` = `fetch` + `merge` --- # Getting Started: Collaboration .pull-left-40[ .move-down-40[ #### ] .li-small[ - `git remote add <name> <url>`<br>Add remote repository - `git remote -v`<br>List remote repository - `git pull <remote> <branch>`<br>Download commits from remote - `git push <remote> <branch>`<br>Upload commits to remote ] ] .pull-right-60[ .move-up-30[ .code-size-12[ ```bash $ git push origin master ``` ] ] {{content}} ] -- <img src="images/07-git/push.png" width="75%" style="display: block; margin: auto;" /> --- # Getting Started: Collaboration .pull-left-40[ .move-down-40[ #### ] .li-small[ - `git remote add <name> <url>`<br>Add remote repository - `git remote -v`<br>List remote repository - `git pull <remote> <branch>`<br>Download commits from remote - `git push <remote> <branch>`<br>Upload commits to remote ] ] .pull-right-60[ #### 🌵 Warning: Always `pull` First .code-small[ ```bash $ git push To https://github.com/username/my-project.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/username/my-project.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. ``` ] ] --- # Getting Started: Collaboration .pull-left-40[ .move-down-40[ #### ] .li-small[ - `git remote add <name> <url>`<br>Add remote repository - `git remote -v`<br>List remote repository - `git pull <remote> <branch>`<br>Download commits from remote - `git push <remote> <branch>`<br>Upload commits to remote - `-u` set upstream ] ] .pull-right-60[ #### 🌵 Warning: Always `pull` First .code-small[ ```bash $ git push To https://github.com/username/my-project.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/username/my-project.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. ``` ] .move-down-30[ #### Setting Upstream ] .code-size-12[ ```bash $ git push -u origin master # or $ git branch --set-upstream-to="<remote/branch>" ``` ] ] --- # Getting Started: Branching -- .pull-left-40[ #### .li-small[ - `git branch <name>`<br>Create local branch ] ] .pull-right-60[ .move-down-50[ .code-size-12[ ```bash $ git branch my-branch ``` ] ] .move-down-50[ {{content}} ] ] -- <img src="images/07-git/branch-extra-1.png" width="100%" style="display: block; margin: auto;" /> --- # Getting Started: Branching .pull-left-40[ #### .li-small[ - `git branch <name>`<br>Create local branch ] ] .pull-right-60[ .move-down-50[ .code-size-12[ ```bash $ git branch my-branch ``` ] ] .move-down-50[ <img src="images/07-git/branch-extra-2.png" width="100%" style="display: block; margin: auto;" /> ] .code-size-12[ {{content}} ] ] -- Remote branch created on `push` ```bash $ git push -u origin my-branch ``` --- # Getting Started: Branching .pull-left-40[ #### .li-small[ - `git branch <name>`<br>Create local branch - `git checkout <name>`<br>Switch to another branch ] ] .pull-right-60[ .move-down-110[ .code-size-12[ ```bash $ git checkout my-branch ``` ] ] ] --- # Getting Started: Branching .pull-left-40[ #### .li-small[ - `git branch <name>`<br>Create local branch - `git checkout <name>`<br>Switch to another branch - `-b` create and move ] ] .pull-right-60[ .code-size-12[ .move-down-110[ ```bash $ git checkout my-branch ``` ] ```bash $ git checkout -b my-branch ``` ] ] --- # Getting Started: Branching .pull-left-40[ #### .li-small[ - `git branch <name>`<br>Create local branch - `git checkout <name>`<br>Switch to another branch - `-b` create and move - `git branch` list branches ] ] .pull-right-60[ .code-size-12[ .move-down-210[ ```bash $ git branch * master my-branch ``` ] ] ] --- # Getting Started: Branching .pull-left-40[ #### .li-small[ - `git branch <name>`<br>Create local branch - `git checkout <name>`<br>Switch to another branch - `-b` create and move - `git branch` list branches - `-vv` verbose - `-r` list remote branches ] ] .pull-right-60[ .move-down-210[ .code-size-12[ ```bash $ git branch * master my-branch ``` ```bash $ git branch -vv * master 00ab7a8 [origin/master] Update master my-branch 702b800 [origin/my-branch] Create my-branch $ git branch -vvr origin/master 00ab7a8 Update master origin/my-branch 702b800 Create my-branch ``` ] ] ] --- # Getting Started: Merging -- .pull-left-40[ #### ] .pull-right-60[ .code-size-12[ ```bash $ git checkout master ``` ] .move-down-44[ <img src="images/07-git/merge-extra-1.png" width="100%" style="display: block; margin: auto;" /> ] ] --- # Getting Started: Merging .pull-left-40[ #### .move-down-50[ .li-small[ - `git merge <name>`<br>Merge branch ] ] ] .pull-right-60[ .code-size-12[ ```bash $ git checkout master $ git merge my-branch ``` ] <img src="images/07-git/merge-extra-2.png" width="100%" style="display: block; margin: auto;" /> {{content}} ] -- > *“Merge commit”* joining the two branches --- # Getting Started: Merging .pull-left-40[ #### .move-down-50[ .li-small[ - `git merge <name>`<br>Merge branch - `git branch -d <branch-name>`<br>Remove local branch - `git push <remote-name> --delete <branch-name>`<br>Remove remote branch ] ] ] .pull-right-60[ .code-size-12[ ```bash $ git checkout master $ git merge my-branch ``` ] .move-down-44[ .code-size-12[ ```bash # Remove local branch $ git branch -d my-branch # Remove remote branch $ git push origin --delete my-branch ``` ] ] ] --- # Getting Started: Conflicts -- .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line Second text line Third text line ``` ] ] ] ] .pull-right-50[ ] --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line Branch-B text line Third text line ``` ] ] ] .pull-right-50[ ] --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line *Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line *Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line *Branch-B text line Third text line ``` ] ] ] .pull-right-50[ ] --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line *Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line *Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line *Branch-B text line Third text line ``` ] ] ] .pull-right-50[ .code-size-12[ ```bash $ git checkout branch-A $ git merge branch-B ``` ] ] --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line *Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line *Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line *Branch-B text line Third text line ``` ] ] ] .pull-right-50[ .code-size-12[ ```bash $ git checkout branch-A $ git merge branch-B Auto-merging my-file.txt CONFLICT (content): Merge conflict in my-file.txt Automatic merge failed; fix conflicts and then commit the result. ``` ] .code-size-12[ {{content}} ] ] -- ```bash #---- my-file.txt First text line <<<<<<< HEAD Branch-A text line ======= Branch-B text line >>>>>>> branch-B Third text line ``` --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line *Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line *Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line *Branch-B text line Third text line ``` ] ] ] .pull-right-50[ .code-size-12[ ```bash $ git checkout branch-A $ git merge branch-B Auto-merging my-file.txt CONFLICT (content): Merge conflict in my-file.txt Automatic merge failed; fix conflicts and then commit the result. ``` ] .code-size-12[ ```bash #---- my-file.txt First text line <<<<<<< HEAD *Branch-A text line ======= *Branch-B text line >>>>>>> branch-B Third text line ``` ] ] --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line *Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line *Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line *Branch-B text line Third text line ``` ] ] ] .pull-right-50[ .code-size-12[ ```bash $ git checkout branch-A $ git merge branch-B Auto-merging my-file.txt CONFLICT (content): Merge conflict in my-file.txt Automatic merge failed; fix conflicts and then commit the result. ``` ] .code-size-12[ ```bash #---- my-file.txt First text line Branch-B text line Third text line ``` ] .code-size-12[ {{content}} ] ] -- ```bash $ git commit -m "Solve conflict" ``` {{content}} -- #### Undo Merge ```bash $ git merge --abort ``` --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line *Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line *Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line *Branch-B text line Third text line ``` ] ] ] .pull-right-50[ #### Conflict Style Diff3 .code-size-12[ {{content}} ] ] -- ```bash $ git config --global merge.conflictstyle diff3 ``` {{content}} -- ```bash #---- my-file.txt First text line <<<<<<< HEAD Branch-A text line ||||||| common ancestor commit Second text line ======= Branch-B text line >>>>>>> merging-branch Third text line ``` --- # Getting Started: Conflicts .pull-left-50[ .move-left-130[ .my-code-block[ #### Original .code-size-12[ ```bash #---- my-file.txt First text line *Second text line Third text line ``` ] ] ] <br> .pull-left-50[ #### Branch A .code-size-12[ ```bash #---- my-file.txt First text line *Branch-A text line Third text line ``` ] ] .pull-right-50[ #### Branch B .code-size-12[ ```bash #---- my-file.txt First text line *Branch-B text line Third text line ``` ] ] ] .pull-right-50[ #### Conflict Style Diff3 .code-size-12[ ```bash $ git config --global merge.conflictstyle diff3 ``` ```bash #---- my-file.txt First text line <<<<<<< HEAD *Branch-A text line ||||||| common ancestor commit *Second text line ======= *Branch-B text line >>>>>>> merging-branch Third text line ``` ] ] --- # Git Workflow -- #### Two Branches approach <img src="images/07-git/workflow-adv-1.png" width="95%" style="display: block; margin: auto;" /> --- # Git Workflow #### Multiple Branches Approach <img src="images/07-git/workflow-adv-2.png" width="95%" style="display: block; margin: auto;" /> --- class: inverse, center, middle # RStudio Git GUI --- # RStudio: Configure Git -- *“Tools -> Global Options”* <img src="images/07-git/git-settings-1.png" width="35%" style="display: block; margin: auto;" /> -- <img src="images/07-git/rstudio-git.png" width="35%" style="display: block; margin: auto;" /> --- # RStudio: Create Git Repository -- .pull-left-50[ #### Create a New Project <img src="images/07-git/rstudio-new-proj.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ {{content}} ] -- #### Clone a Remote Repository <img src="images/07-git/rstudio-clone-1.png" width="85%" style="display: block; margin: auto;" /> --- # RStudio: Create Git Repository .pull-left-50[ #### Create a New Project <img src="images/07-git/rstudio-new-proj.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ #### Clone a Remote Repository <img src="images/07-git/rstudio-clone-2.png" width="85%" style="display: block; margin: auto;" /> ] --- # RStudio: Create Git Repository .pull-left-50[ #### Create a New Project <img src="images/07-git/rstudio-new-proj.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ #### Clone a Remote Repository <img src="images/07-git/rstudio-clone-3.png" width="85%" style="display: block; margin: auto;" /> ] --- # RStudio: Git Panel .pull-left-50[ #### <img src="images/07-git/panel-base-1.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ ] --- # RStudio: Tracking Changes -- .pull-left-50[ #### <img src="images/07-git/panel-files.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ #### .li-small[ {{content}} ] ] -- - <img src="images/07-git/icon-untraked.png" height="40"> Untracked - <img src="images/07-git/icon-added.png" height="40"> Added - <img src="images/07-git/icon-modified.png" height="40"> Modified - <img src="images/07-git/icon-deleted.png" height="40"> Deleted - <img src="images/07-git/icon-renamed.png" height="40"> Renamed - <img src="images/07-git/icon-conflict.png" height="40"> Conflict --- # RStudio: Tracking Changes .pull-left-50[ #### <img src="images/07-git/panel-stage.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ #### .li-small[ - <img src="images/07-git/icon-untraked.png" height="40"> Untracked - <img src="images/07-git/icon-added.png" height="40"> Added - <img src="images/07-git/icon-modified.png" height="40"> Modified - <img src="images/07-git/icon-deleted.png" height="40"> Deleted - <img src="images/07-git/icon-renamed.png" height="40"> Renamed - <img src="images/07-git/icon-conflict.png" height="40"> Conflict ] ] --- # RStudio: Tracking Changes .pull-left-50[ #### Staging and Commiting <img src="images/07-git/panel-commit.png" width="100%" style="display: block; margin: auto;" /> ] .pull-right-50[ {{content}} ] -- <img src="images/07-git/rstudio-diff-2.png" width="85%" style="display: block; margin: auto;" /> {{content}} -- <img src="images/07-git/panel-commit-2.png" width="85%" style="display: block; margin: auto;" /> {{content}} -- <img src="images/07-git/panel-revert.png" width="85%" style="display: block; margin: auto;" /> --- # RStudio: Tracking Changes .pull-left-50[ #### History <img src="images/07-git/panel-base-2.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ #### {{content}} ] -- <img src="images/07-git/panel-history.png" width="100%" style="display: block; margin: auto;" /> --- # RStudio: Tracking Changes .pull-left-50[ #### History <img src="images/07-git/panel-base-2.png" width="85%" style="display: block; margin: auto;" /> <img src="images/07-git/panel-history-2.png" width="65%" style="display: block; margin: auto;" /> ] .pull-right-50[ #### <img src="images/07-git/panel-history.png" width="100%" style="display: block; margin: auto;" /> ] --- # RStudio: Managing Collaboration -- .pull-left-50[ #### .code-small-12[ ```bash $ git remote add <remote-name> <remote-URL> ``` ] {{content}} ] .pull-right-50[ ] -- <img src="images/07-git/panel-base-3.png" width="85%" style="display: block; margin: auto;" /> --- # RStudio: Branching and Merging -- .pull-left-50[ #### Change Branch <img src="images/07-git/panel-base-4.png" width="85%" style="display: block; margin: auto;" /> ] .pull-right-50[ {{content}} ] -- #### New branch <img src="images/07-git/panel-base-5.png" width="85%" style="display: block; margin: auto;" /> {{content}} -- <img src="images/07-git/panel-new-branch.png" width="65%" style="display: block; margin: auto;" /> --- class: inverse, center, middle # Git: your only real friend when programming! ## Moving to the next step...