28
Using git to download and update BOUT++ Peter Hill ER Meeting|14th Sept 2015|1/28

Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Using git to download and update BOUT++

Peter Hill

ER Meeting|14th Sept 2015|1/28

Page 2: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Outline

What is git?

Getting git

Basic git usage

Getting BOUT++

Compiling BOUT++

Running examples

Contributing to BOUT++

ER Meeting|14th Sept 2015|2/28

Page 3: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

What is git?

Version Control System (VCS)

Version control systems record changes to a file/set of files over time

Not just software! This talk is under git

Allows you revert files back to a previous state, compare changesover time, see who last modified something, etc.

Local VCS

Naive versioning: separate folders for each version

Slightly better: local database of changes

ER Meeting|14th Sept 2015|3/28

Page 4: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

What is git?

Centralised vs Distributed VCS

Centralised VCSs: CVS, Subversion

Have a single server than contains all the versioned files

Can see what other people are working on

Easier to administer a centralised VCS than local databases on eachclient

If server goes down, can lose access to project history, etc.

If central database is lost, everything not backed-up is lost

Distributed VCSs: git, mercurial

Clients don’t just checkout latest snapshot of files, repository is fullymirrored

If server goes down, any client repo can be copied back to server torestore it

Multiple remote repos work pretty well

ER Meeting|14th Sept 2015|4/28

Page 5: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

How does it work?

Snapshots

git thinks of its data like a setof snapshots of a miniaturefilesystem.

Every time you commit, it takesa picture of what all your fileslook like and stores a referenceto that snapshot

ER Meeting|14th Sept 2015|5/28

Page 6: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

git is local

Vast majority of operations are local

Doesn’t need to talk to remote servers to get e.g. history

This means you can continue to work offline, including committingchanges to the database

Checking out a copy of the repository means you have a full copy

You can copy your local version onto a USB stick and hand it tosomeone

They now have access to the project history, can make changes, etc.

ER Meeting|14th Sept 2015|6/28

Page 7: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

git has integrity

Everything in git is check-summed

References are to checksums

git can immediately detect if data gets lost in transit or files arecorrupted

Checksums are done using SHA-1:

24b9da6552252987aa493b52f8696cd6d3b00373

git stores everything, not by name, but by hash value of its contents

ER Meeting|14th Sept 2015|7/28

Page 8: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

The Three States

Important to understandcorrectly

Three main states that filescan be in:

1 Committed: data storedin repo

2 Modified: file is changedbut not committed

3 Staged: modified filemarked to go into nextcommit

ER Meeting|14th Sept 2015|8/28

Page 9: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Getting git

Linux

Get git through your package manager:

sudo yum install git

sudo apt-get install git

sudo zypper install git

Mac

Install Xcode Command Line Tools, then try to run git. If you don’thave it installed already, it will prompt you to install it.

More up-to-date version: http://git-scm.com/download/mac

Alternatively, use GitHub for Mac: http://mac.github.com

ER Meeting|14th Sept 2015|9/28

Page 10: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Getting git

Windows

Official build: http://git-scm.com/download/win Note that this isactually “Git for Windows”

Alternatively, use GitHub for Windows: http://windows.github.com

From source

Download tarball from either https://github.com/git/git/releases orhttps://www.kernel.org/pub/software/scm/git

Compile and install, then you can get git via git!

ER Meeting|14th Sept 2015|10/28

Page 11: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Getting a repo

Two choices: import an existing project into git, or clone an existinggit repo from somewhere else

Initialise a repository

Go to project’s directory:

git init

Creates a new subdirectory names .git containing all the necessaryrepo files

Nothing in project is tracked yet

ER Meeting|14th Sept 2015|11/28

Page 12: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Cloning an existing repository

# Clones into ./BOUT-dev

git clone https://github.com/boutproject/BOUT-dev.git

# Clones into ./BOUT++

git clone https://github.com/boutproject/BOUT-dev.git BOUT++

Doesn’t just get a working copy - git receives a full copy of nearly alldata that the server has

This used the HTTPS protocol, but you can also use SSH likeuser@server:path/to/repo.git

To use SSH on GitHub, add your (public!) SSH key to your GitHubprofile

ER Meeting|14th Sept 2015|12/28

Page 13: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Lifecycle of a file

ER Meeting|14th Sept 2015|13/28

Page 14: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Getting help

git help <command>

git <command> --help

git <command> -h

man git-<command>

ER Meeting|14th Sept 2015|14/28

Page 15: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Checking status

git status

git status -s

ER Meeting|14th Sept 2015|15/28

Page 16: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Tracking new files

git add <filename>

git add *.cxx

ER Meeting|14th Sept 2015|16/28

Page 17: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Staging modified files

git add <changed file>

ER Meeting|14th Sept 2015|17/28

Page 18: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Ignoring files

.gitignore

ER Meeting|14th Sept 2015|18/28

Page 19: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Viewing changes

git diff

git diff --staged

git diff <filename>

git difftool --tool=meld

ER Meeting|14th Sept 2015|19/28

Page 20: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Committing changes

git commit

git commit -m "Useful commit message"

git commit -a -m "This commits everything"

ER Meeting|14th Sept 2015|20/28

Page 21: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Removing files

git rm <filename>

Doesn’t delete file! Just removes it from git repo

ER Meeting|14th Sept 2015|21/28

Page 22: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Moving files

git mv <old file> <new file>

This is synonym for

mv <old file> <new file>

git rm <old file>

git add <new file>

ER Meeting|14th Sept 2015|22/28

Page 23: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Viewing project history

git log

Huge amount of options here

Add to your .gitconfig

ER Meeting|14th Sept 2015|23/28

Page 24: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Getting BOUT++

Use git to clone the repository:

# Clones into ./BOUT-dev

git clone https://GitHub.com/boutproject/BOUT-dev.git

# Clones into ./BOUT++

git clone https://GitHub.com/boutproject/BOUT-dev.git BOUT++

ER Meeting|14th Sept 2015|24/28

Page 25: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Compiling BOUT++

Basic configure and make:

./configure --with-lapack --with-netcdf

make

Then check examples work:

cd ./examples

./test_suite_make

./test_suite

ER Meeting|14th Sept 2015|25/28

Page 26: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Submitting a bug report

Open an issue on GitHub

ER Meeting|14th Sept 2015|26/28

Page 27: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Contributing to BOUT++

1 Create a new branch

git branch my-new-feature

git checkout my-new-feature

2 Make changes

3 Run test suite if necessary

4 Commit (with a nice message!)

git add README.md

git commit -m "Fiddle with contributing section in README"

5 Push to GitHub

git push

6 Submit pull request

ER Meeting|14th Sept 2015|27/28

Page 28: Using git to download and update BOUT++ · Using git to download and update BOUT++ Peter Hill ER Meetingj14th Sept 2015j1/28. Outline What is git? Getting git Basic git usage Getting

Acknowledgments

Some material from Pro Git, Second Edition by written by Scott Chaconand Ben Straub and published by Apress. Available here:https://git-scm.com/book

Licensed under Creative Commons Attribution Non-Commercial ShareAlike 3.0 Licence.

ER Meeting|14th Sept 2015|28/28