version Control And Collaboration With Git And Github · Version Control and collaboration with Git...

58
Version Control and collaboration with Git and Github Katia Oleinik Research Computing Services

Transcript of version Control And Collaboration With Git And Github · Version Control and collaboration with Git...

Page 1: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Version Control and collaboration with

Git and Github

Katia Oleinik

Research Computing Services

Page 2: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Challenges of working on a project

• Undo and Redo• Tracking changes• Working with others• Sharing Changes• Overlapping work by various people

Page 3: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git history

Development began in 2005 while working on Linux KernelThe first stable version released in December 2005

Goals set but Linus Torvalds: Distributed system Applying updates should not take longer than 3 seconds Take Concurrent Version System as an example of what not to do Support distributed system workflow Include strong safeguards against corruption, both accidental and malicious

Word "git" - "unpleasant person" in British slang

The man page describes Git as "the stupid content tracker".

From README file of the source code: "- global information tracker": you're in a good mood,

and it actually works for you. Angels sing, and a light

suddenly fills the room.

- "g*dd*mn idiotic truckload of sh*t": when it breaks

Page 4: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git main features

Track all your changes

Work along with others

Share work with others

Page 5: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git Workflow

Create a branch

Start with a clean working directory

Make some changes

Create a snapshot

Make a commit

repeat

Pull and Push to a repository

when ready

Page 6: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git TerminologyRepository - container for snapshots and historyRemote - connection to another repository for example GitHub (like URL)Commit -

• A snapshot, basic unit of history• Full copy of a project• Includes author, time, comments, pointer to the parent

Reference - a pointer to commitBranch - a separate line of workflowMerge - a commit that combines 2 lines of history (points to 2 parents)

Page 7: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Installing Git

Page 8: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Login to the SCC

Username: tuta#Password:

# - is the number located on your computer

Note: • Username and password are case-sensitive• password will not be displayed while you

are typing it

Page 9: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : basic configuration

# select the latest version of git (SCC only)

# check git version

Page 10: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : basic configuration

Notes: • Vim is the default editor used by git• Select gedit if you are not familiar with vim or emacs editors

Interpreter program

command flag key value

Page 11: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : basic configuration

Page 12: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : advanced configuration

System

• Usually in /etc directory

Global

• ~/.gitconfig

Local

• .git/config

overrides

overrides

Page 13: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : create a repository

# create a project with a name mypy

# change directory (go inside project directory)

# list the files in the directory including those starting with a dot

Page 14: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : explore a repository

Page 15: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : 4 statuses

• File is not under control by gituntracked

• Git knows about file, but it has not been modifiedunmodified

• Git knows about the file and it has been modifiedmodified

• File is ready to commitStaged

Page 16: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : check the status

Page 17: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Create a new file

Using your favorite editor, open a file hello.py and enter the following content:

Note: if you are not familiar with vim or emacs editors, used gedit to edit files:

gedit hello.py

Save the file with the name hello.py and exit.

Page 18: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Execute python script (optional)

Page 19: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : check the status

Page 20: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : add file to the repository

# add file to git repository

#check status

Staged file

Page 21: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : commit

Note: Make sure to enter clear, concise and meaningful comments about your commits!

Page 22: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Modify a file that is tracked by git

Using your favorite editor, modify existing python code

Save the file and exit.

Page 23: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Create a new README file

Using your favorite editor create README file and add some content:

Save the file and exit.

Page 24: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : check the status

hello.py has status "modified". Gitknows about this file, but reminds that the file has been modified since the last commit

README has status "untracked". Git has no information about this file.

Page 25: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : add files to a staging area

Note: Files can be added one by one or listed together

Page 26: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : commit

Page 27: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : commit

Page 28: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : view the history of commits

SHA-1 key (Secure Hash Algorithm 1)

Note: Git uses SHA-1 only to produce a unique hash tag

Page 29: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Modify a hello.py file again

Using your favorite editor, modify existing python code

Save the file and exit.

Page 30: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Execute modified version of hello.py (optional)

Page 31: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : add and commit file

Practice: check the status and view the log of commits.

Page 32: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : view log with a graph

Page 33: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : one line log

Page 34: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : graphical tool

Page 35: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : reviewing previous commits

Note: Only first 7 symbols of SHA-1 key are necessary to identify the checkout

Page 36: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : returning back to the last commit

Page 37: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : hard delete of the latest commits

Page 38: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : Renaming the files (git way)

#commit

#rename the file and add changes to the staging area

Page 39: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : Renaming the files (outside git)

#commit #add both files (!) to staging area

Page 40: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : Deleting the files (git way)

#create a file

#add file to staging area

#commit

#delete file and add changes to a staging area

#commit

Page 41: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : Deleting the files (outside of git)

#report changes to a staging area

#commit

Page 42: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git : ignore some files

Page 43: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Submitting work to remoteGitHub, GitLab, Bitbucket, etc.

Page 44: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Login to the account

Page 45: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Start a new project

Page 46: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Connect your local repo to the remote

Page 47: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Connect your local repo to the remote

Page 48: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

View remote github repositories

Page 49: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

View remote github repositories

Page 50: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Cloning remote repository

Page 51: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Clone Remote repository

Page 52: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Clone Remote repository

# change directory

# remove old repository

# clone remote repository

Page 53: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Clone Remote repository

Page 54: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Thank you!Please, fill out evaluation:

Page 55: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Apendix

Page 56: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git help

Page 57: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git help

Page 58: version Control And Collaboration With Git And Github · Version Control and collaboration with Git and Github ... Deleting the files (git way) ... #add file to staging area #commit

Git resources

Git official manual:https://git-scm.com/documentation

Easy online tutorial by GitHub:https://try.github.io

Git Immersion (popular Git tutorial):http://gitimmersion.com/

Git docs on many languages:http://www-cs-students.stanford.edu/~blynn/gitmagic/