databinge: version control with git · 1. sign up for a git account 2. basic git commands and their...

28
Databinge: Version Control with Git Nov. 22, 2019 Glaynel Alejo

Upload: others

Post on 24-Jul-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Databinge: Version Control with Git

Nov. 22, 2019

Glaynel Alejo

Page 2: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

O

U

T L

I

N

E Talk:1. What is Version Control?2. Why should I use it?3. Git4. GitKraken

Tutorial:1. Sign up for a git account2. Basic git commands and their equivalent actions in GitKraken:

a. git initb. git addc. git commit d. git push

e. git pullf. git diffg. git reverth. git reset

Conclusion:1. GUI vs. CLI2. Open Science Framework and osfclient

Page 3: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

V E R S I O N

● a way of tracking changes to files (text, code, images, etc.)

● enables seamless, asynchronous collaboration on a project while ensuring significant progress is preserved and secure

C O N T R O L

Page 4: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

In case of emergency, break the version control glass.

File recovery and backup Versioning Attribution Changelog

Computer crash? Accidental deletion? Corrupted file? No

problem.

work remotely

Make experimental

changes without relying on the

undo button to save you.

A record of user contributions

allows credit to be given where

credit is due.

Why did I do that?

History of changes and

why you made them.

Page 5: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Git is a popular, open-source distributed version control system.

● open-source = free, modifiable● distributed = every user has a full,

local copy of the project

Commands can be executed from the command line or through an

application.

GitHub hosts Git repositories.

Git

https://xkcd.com/1597/

Page 6: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

GitKraken

GitKraken is a free Git GUI client for Windows, Mac, and Linux.

It takes less than a minute to download and install. Try it now:

https://www.gitkraken.com/download

Documentation

Download

Video Tutorial

Page 7: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Let’s git on with it.

Documentation Resources Troubleshooting

Create a git account

(Dangit, git!)

https://github.com/join

Open GitKraken from your desktop

Sign in with GitHub

Page 8: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git init

Click: File > Init Repo

Click: GitHub.com

Fill in each field

Click: Create Repository and Clone

Clone after init = create a copy of the repository on your computer

Set Access to Public. GitKraken Free does support opening of private repos. !

Page 9: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Create a (text) file

Right-click the side panel: Create File

Name your file “test.txt”

!Add the extension to the end of the file name to

specify file type, i.e. “filename.txt”

The centre panel is a graph of your repo’s history

Page 10: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git add [file]

Type “Welcome” in line 1

Click: Stage File

Click the x button to exit

CTRL + S to save

indicates unsaved changes made to the file !

The inverse command is git rm = delete file

and stage the deletion

Page 11: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git commit [file] -m “Insert message here”

+ 1 indicates that there is 1 staged file to be committed !

Describe the change you made to the file under

Commit Message

Click: Commit changes to 1 file

Page 12: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git push origin master

Click: Push to upload the committed changes to the

remote server (GitHub)

Page 13: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Change the file on GitHub

Log in to GitHub

Click on the file you created within the databinge repo

Click on the pen beside the trash can to Edit this file

Delete the first line and replace it with “See you soon!”

Page 14: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Commit the change on GitHub

Scroll down to Commit changes

Note the default commit message: “Update test.txt”!

It’s best practice to write specific, descriptive commit

messages.

Click: Commit changes

Page 15: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git pull

GitKraken knows a change has been made to the

remote repo but master remains at the last local

commit until a pull is made

!

Click: Pull to download the changes made on GitHub

to your local repo

Page 16: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git diff

Click on the file from the side panel in the home

page

Click: Diff View

Click on to Split View

Page 17: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

“Whoopsie-daisy!”

git revert git resetvs.

Undo a commit by making a new commit

● for public commits, i.e. those that have been pushed to the remote repo or in a public branch

● does not rewrite the commit history

Drop commits with/without keeping changes

● for commits that have not been pushed or made in a private branch

--soft = keep dropped commits as staged changes--mixed = keep dropped commits as unstaged changes--hard = delete dropped commits

https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting

Page 18: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git revert [commit-ID]

Right-click the Update test.txt

commit

“Oops, let’s go back to welcome.”

Click: Revert commit

Click: Push

Page 19: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Practice: Make 2 more commits (but don’t push!)

Add your name to line 2 then commit

Add the date to line 3 then commit

Origin and local (laptop icon) are not located at the same

commit (Why?)!

Page 20: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

git reset [commit-ID] --mixed

Right-click the Revert “Update test.txt”

commit

“Nevermind, I want the welcome message and

the date only.”

Hover over Reset master to this commit and click:

Mixed - keep working copy but reset index

(step 1)

Page 21: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Click: test.txt in the side panel under Unstaged Files (1)

Hover over line 3 and click on to Stage this line

Commit!“Add date to

welcome message”

git reset [commit-ID] --mixed (step 2)

Page 22: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Click on the trash can to Discard all changes and

get rid of line 2 (your name) as an unstaged

change

Click: Push to send the committed changes to

the remote repo

You can also git stash(store) a change then git stash pop when you’re

ready to commit it.

(step 3)git reset [commit-ID] --mixed

Page 23: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git
Page 24: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

GUI vs. CLI: Which one should I commit to?

GUI:● faster● more efficient● makes commands much easier to execute (e.g. no need to keep track of commit

IDs)● easier troubleshooting● no previous experience/skill required● visualize changes

Say no to GUI-shaming

If you are comfortable with CLI, go for it but at least try using a GUI.

Page 25: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

GitHub Desktop

GitHub Desktop is a free GUI for Windows and Mac.

● less functionalities● can open private repos

DocumentationDownload

Git a GUI that works for you!

Page 26: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

osfclient

Open Science Framework

OSF is a free and open-source data management (sharing and storage)

platform.

● OSF Storage location can be set to Montreal

● 5GB limit on individual files● private and public projects● easily generate DOI, license, citation● access to Dropbox, Google

applications (Docs, Sheets, etc.), GitHub, etc.

Learn more about OSF in the Brain Circuits Cluster Data Management White Paper

osfclient

osfclient is a Python module and command-line program for executing simple actions on OSF, such as uploading and downloading files and

folders.

I made a tutorial on osfclient (both the module and command-line tools) which is available as a Jupyter notebook on GitHub.

https://github.com/ubcbraincircuits/osfclienttutorial

View the notebook in a browser here!

Page 27: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

S U

M M

A R

Y

The what, why, and how of version control:

The what:● Git = VC system● GitKraken = Git GUI● GitHub = hosts GIT repos● GitHub Desktop = another Git GUI

The why:● Reasons to use VC: file recovery and backup, versioning, attribution,

changelog● Reasons to use a GUI: less work, more fun

The how:● Execute git init, git add, git commit, git push, git

pull, git diff, git revert, git reset in GitKraken

(.....and Open Science Framework and an osfclient Jupyter notebook)

Page 28: Databinge: Version Control with Git · 1. Sign up for a git account 2. Basic git commands and their equivalent actions in GitKraken: a.git init b.git add c.git commit d.git push e.git

Does everyone git it?

Any questions?