Introduction to github using Egit

Post on 28-Aug-2014

156 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

For laboratory seminar. Introduction to Github using Egit.

Transcript

Introduction to Github with Egit

2014/YuMatsuzawa/

Github??

• Google it, now.

• Or, https://github.com/

Introduction to Github 2

Github??

Introduction to Github 3

Github??

Introduction to Github 4

Make your account, now.

Github??

Introduction to Github 5

Make your account, now.

Or, Login if already got one.

You will see…

Introduction to Github 6

You will see…

Introduction to Github 7

…then you are ready.

LOLWATTZDIS?

• With Github, you can…– Find/Clone/Help someone else’s nice projects.– Sync your progress across multiple machines.– Roll back your project to previous state. – Publish/Share your project.

• “Git” is one of many Version Control Systems (VCS).• Github is one of public platforms (hubs) of Git.

Introduction to Github 8

LOLWATSDIS?

• With Github, you can…– Find/Clone/Help someone else’s nice projects.– Sync your progress across multiple machines.– Roll back your project to previous state. – Publish/Share your project.

• “Git” is one of many Version Control Systems (VCS).• Github is one of public platforms (hubs) of Git.

Introduction to Github 9

• Seems nice, but what is ‘cloning’? Cloning a project is basically copying it to

your machine/environment to extend it as you like.

You can clone any public projects including very famous one such as jQuery (/jQuery/jQuery)

• How to help someone? Clone their project, modify, and offer

your help as ‘pull request’ (covered later)

LOLWATSDIS?

• With Github, you can…– Find/Clone/Help someone else’s nice projects.– Sync your progress across multiple machines.– Roll back your project to previous state. – Publish/Share your project.

• “Git” is one of many Version Control Systems (VCS).• Github is one of public platforms (hubs) of Git.

Introduction to Github 10

• Thanks a bunch! But how? Covered later in detail; in a few words:

1. Uploading your progress to Github2. Downloading it to other machines3. (Conflict shall be checked/marked)

• Is it automatic? NO. Why? Covered later.

LOLWATSDIS?

• With Github, you can…– Find/Clone/Help someone else’s nice projects.– Sync your progress across multiple machines.– Roll back your project to previous state. – Publish/Share your project.

• “Git” is one of many Version Control Systems (VCS).• Github is one of public platforms (hubs) of Git.

Introduction to Github 11

• Why this is important? When you mess up with your project and

it stops working (happens often), you can come back to the point it had worked.

• To any states before? Any limit? No limitation. Github doesn’t have “max

space.” You’ll see why.

LOLWATSDIS?

• With Github, you can…– Find/Clone/Help someone else’s nice projects.– Sync your progress across multiple machines.– Roll back your project to previous state. – Publish/Share your project.

• “Git” is one of many Version Control Systems (VCS).• Github is one of public platforms (hubs) of Git.

Introduction to Github 12

• Could be useful… but can I keep it private? NO. This is why github is free AND space-

unlimited. Projects uploaded on github is considered public assets(or Open Source Software) thus forcibly published.

• Really? …Unless you pay at least $7/month.

Now you know Github is

• Platform of distributed development for Open Source Software using Git– Actually, not limited to software. Any contents can

be managed on github (images, .doc, .xls, etc.)– You must acknowledge contents on Github is

published, thus you shouldn’t upload restricted contents (such as data including private info.)

– Let’s delve into “How”

Introduction to Github 13

From Where?

• Basic Git is CUI thing

– You may learn/use Git this way, and actually, sometimes, for some kind of people, it’s even easier. But for now…

• Let’s do this from Eclipse GUI (for Java users)

Introduction to Github 14

Requirement

• Any working Eclipse (not too old one)• ssh-keygen– Included in recent versions of Eclipse– Other ways:

• On Mac/Linux this is innately installed• On Windows:

– If you have cygwin installed, you’re OK.– If you have PuTTY or TeraTerm installed, you’re OK.– Otherwise, install TeraTerm.

» PuTTY and TeraTerm are both terminal emulator. For OpenSSH keygen purpose, TeraTerm is simpler and easier.

Introduction to Github 15

EGit

• … is Eclipse plugin for Git.• Install it.

1. Launch Eclipse2. Help > Eclipse Marketplace3. Search “EGit”4. Install

Introduction to Github 16

Prepare SSH public key

• Stay in Eclipse• Open “ 設定” (Preferences )– “ 一般” (General)>” ネットワーク接続” (Network Connection)>”SSH2”– “ 鍵管理” (Key Management)– “RSA 鍵の生成” (Generate RSA Key)– “ 秘密鍵の保管” (Save Private Key)• Default name would be “id_rsa”• Path should be <user>/.ssh/

Introduction to Github 17

Prepare SSH public key• If you already got one, new key isn’t required– Found “<user>/.ssh/id_rsa.pub” ? => Done.

• On Mac/Linux or Cygwin:– Launch Terminal or Cygwin– Type “ssh-keygen”

• Save/Move your key under <user>/.ssh/

• On TeraTerm:– Cancel “ 新しい接続”– “ 設定” > “SSH 鍵生成”

• Save under <user>/.ssh/

Introduction to Github 18

Prepare SSH public key

• On PuTTY:– Find PuTTYGen in PuTTY install directory– “ 生成” (Generate)– (Move cursor around)– “ 変換” (Convert)

>“OpenSSH 形式”• This is for private key

– Save as appropriate name• Default: <user>/.ssh/id_rsa• No extension needed

Introduction to Github 19

Prepare SSH public key

– Copy this• PuTTYGen generate original format ssh key• OpenSSH format key required• This is for pubic key

– Open text editor– Paste– Save as appropriate name• Default: “id_rsa.pub”

Introduction to Github 20

Register public key

Introduction to Github 21

Register public key

Introduction to Github 22

Register public key

Introduction to Github 23

Register public key

Introduction to Github 24

Register public key

Introduction to Github 25

Register public key

Introduction to Github 26

Register public key

Introduction to Github 27

Register public key

Introduction to Github 28

Paste the content of generated id_rsa.pub here

Appropriate title

Specify SSH private key for Eclipse

• Generated your key via Eclipse? => Done.• If not:– Your key is <user>/.ssh/id_rsa? => Done.– If not:• Open “ 設定”• “ 一般” >” ネットワーク接続” >”SSH2”• “ 秘密鍵の追加” (Add Private Key)• Specify your key name

– Make sure it’s stored under <user>/.ssh/

Introduction to Github 29

Authentication Method

• “ 認証方法” (Authentication Methods)• Uncheck “password”– Only key authentication

• Now everything ready!

Introduction to Github 30

Create Repository

• What’s “repository”?– Storage for Git objects– There must be remote repository on Github AND

local repository on your machine– Concept: Transactions are done between

repositories (specific locations)

Introduction to Github 31

Create Remote Repository

Introduction to Github 32

Create Remote Repository

Introduction to Github 33

Create Remote Repository

Introduction to Github 34

Create Remote Repository

Introduction to Github 35

Appropriate title

Description

Cannot choose Private on unpaid account

Make README

Create Remote Repository

Introduction to Github 36

Done.

Share your existing project

• Open your project• Right click• チーム” Team”• プロジェクトの共用 “ Share the project”• “Git”

Introduction to Github 37

Create Local Repository

Introduction to Github 38

Create Local Repository

• Where to reposit?– Recommended: Distinct, new path dedicated only for

that repository outside of Eclipse workspace• Not the same as the already existing project directory

(usually in Eclipse workspace)• Why? -> Several reasons. Primarily for future use when you

would want to place multiple projects in that repo.• Faster (Git only cares about files inside the repo)

– Easier to understand: Project directory• No need to move files (easier to initialize)• Sometimes slower (Git starts to check files in workspace)

Introduction to Github 39

Create Local Repository

• Where to reposit?– Recommended: Distinct, new path dedicated only for

that repository outside of Eclipse workspace• Not the same as the already existing project directory

(usually in Eclipse workspace)• Why? -> Several reasons. Primarily for future use when you

would want to place multiple projects in that repo.• Faster (Git only cares about files inside the repo)

– Easier to understand/start: Project directory• No need to move files (easier to initialize)• Sometimes slower (Git starts to check files in workspace)

Introduction to Github 40

…If you are certain about 1 project <-> 1 repo philosophy

Go to

Create Local Repository

Introduction to Github 41

Create Local Repository

Introduction to Github 42

Create Local Repository

Introduction to Github 43

Create Local Repository

Introduction to Github 44

Aforementioned recommendation

Ignore warning and create repo

Create Local Repository

• If you are to place your repo outside of Eclipse workspace…

Introduction to Github 45

Create Local Repository

• If you are to place your repo outside of Eclipse workspace…

Introduction to Github 46

Default path would be /<user>/git/After proceeding, project migration to new path will begin.

Introduction to Github 47

Repository Ready

Introduction to Github 48

Repository Ready

Open Git repositories pane.ウィンドウ > ビューの表示 > その他 >チーム

Indicators appeared(‘>’,’?’,’[NO-HEAD]’,…)

A little backtracking

• It’s good time to learn how exactly Git works.

Introduction to Github 49

A little backtracking

• It’s good time to learn how exactly Git works.

Introduction to Github 50

GithubYour Machine

Your Eclipse

A little backtracking

• You’ve created repositories.

Introduction to Github 51

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

A little backtracking

• Obviously, you want to store your project.

• …but making repository is just a first step.

Introduction to Github 52

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

A little backtracking

• Inside repos are indexes (file lists)

• Indexes track what files belong to the repos

Introduction to Github 53

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-…-…-…

Index-…-…-…

A little backtracking

• Inside repos are indexes (file lists)

• Indexes track what files belong to the repos

• You can ‘git add’ to the index

Introduction to Github 54

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

‘git add’!!

Added!

A little backtracking

• Now the local repo knows your files

• But only their existence.• Repo must know if files are

ready to be shared/launched

Introduction to Github 55

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

A little backtracking

• Your next move is to register your progress

• •

Introduction to Github 56

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

A little backtracking

• Your next move is to register your progress.

• ‘git commit’ is the way to go.• Records your current progress

on indexed files to the repo.

Introduction to Github 57

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

‘git commit’!!

A little backtracking

• You commit to a specific “branch”

• Branch = Front-ends of devel. flows (latest commits)

First commit creates ‘master’

Introduction to Github 58

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

masterCreated!

A little backtracking

• If you modify your files and commit again,

Introduction to Github 59

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

‘git commit’!!

master

c00

A little backtracking

• If you modify your files and commit again,

• …that records are committed to currently targeted branch (in this case ‘master’). New one becomes branch.

Introduction to Github 60

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01

A little backtracking

• You can make another branch

Introduction to Github 61

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01 c02 c03

another

A little backtracking

• You can make another branch

• Committing to another branch will separate the flow.

Introduction to Github 62

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01 c02 c03

a01a00

another

A little backtracking

• You can make another branch

• Committing to another branch will separate the flow.

• Also you can merge them.

Introduction to Github 63

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01 c02 c03

a01a00

m00

A little backtracking

• If branches conflict (like edited same file),

Introduction to Github 64

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01 c02 c03

a01a00

another

A little backtracking

• If branches conflict (like edited same file),

• …Git notifies conflicting files.

Introduction to Github 65

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01 c02 c03

a01a00

another

A little backtracking

• If branches conflict (like edited same file),

• …Git notifies conflicting files.• Then you must manually fix

conflicts then add again.

Introduction to Github 66

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01 c02 c03

a01a00

another

Fix & ‘git add’!!

A little backtracking

• If branches conflict (like edited same file),

• …Git notifies conflicting files.• Then you must manually fix

conflicts then add again.

Introduction to Github 67

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

master

c00 c01 c02 c03

a01a00

m00

A little backtracking

• Anyway, let’s go committing for now!

• Back to Eclipse…

Introduction to Github 68

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

masterCreated!

Introduction to Github 69

Add/Commit

Indicators appeared(‘>’,’?’,’[NO-HEAD]’,…)

Introduction to Github 70

Add/Commit

These indicator means:> -Uncommitted changes exists? -Not added to the index* -Added but uncommitted (‘staged’)[<branch name>] -Current branch**

**Pointer/cursor to current branch is called ‘HEAD’. ‘NO-HEAD’ means no branch specified.

Indicators appeared(‘>’,’?’,’[NO-HEAD]’,…)

Introduction to Github 71

Add/Commit

• Right click on the project,• “ チーム” (Team),

• You’ll find its contents changed• “ コミット” (Commit)

• (You can do the same thing by right-clicking the repository from the repositories pane.)

Introduction to Github 72

Add/Commit

• (This window can differ from an Eclipse version to another, this is Juno 4.2.2)

• Commit Message is important feature used for explaining what changes are made.• Keep it simple but understandable

• If there are untracked files, you can add them here. (Check this “Show untracked”)

Hit “Commit” if messages/adding files are ready

Add/Commit

• Gratz! Your first LOCAL commit (+ add) is made.

• You notice the ‘>’ indicator disappeared from the project.– This means the local repository

now stored your progress.

Introduction to Github 73

“Remote Control”

• Next step is to interact with the remote repo.

Introduction to Github 74

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

masterCreated!

“Remote Control”

• Next step is to interact with the remote repo.

• Remote contents are managed with similar branch system.

• On repo creation, remote ‘master’ was also made.

Introduction to Github 75

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

master

r00

master

“Remote Control”

• Now, you need special local branch.

Introduction to Github 76

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-… r00

masterc00

master

“Remote Control”

• Now, you need special local branch.

• So-called “remote tracking”• This branch tracks/syncs with

status of remote branch.

Introduction to Github 77

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-… r00

master

r00

origin/master

c00

master

“Remote Control”

• ‘origin’ means it’s your primary remote repo.

• ‘origin/master’ means it syncs with ‘master’ branch on your remote repo.

Introduction to Github 78

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-… r00

master

r00

origin/master

*These are just a common tactics to name a remote tracker. You may name yours as you want.

c00

master

“Remote Control”

• Tracker will ‘git fetch’ the remote contents.

• The first fetch creates the remote tracker.

Introduction to Github 79

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-… r00

master

r00

origin/master Created!‘git fetch’!!

c00

master

“Remote Control”

• Then you merge 2 local branches.

Introduction to Github 80

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

master

r00

master

r00

origin/master

“Remote Control”

• Then you merge 2 local branches.

• Now local ‘master’ contains all contents from local & remote.

Introduction to Github 81

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

master

r00

master

r00

origin/master

m00

*In distributed developments, conflicts can happen on this phase.**If you followed this instruction, local ‘master’ contains your local project and initially created README from remote at this moment.

“Remote Control”

• With fetch & merge, local branch is up-to-date

• Normally you do this before starting your work of the day.

• You may just ‘git pull’ here.

Introduction to Github 82

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

master

r00

master

r00

origin/master

m00

*Pull basically means ‘fetch then merge’ combined.

“Remote Control”

• Next move obviously, is going opposite way

Introduction to Github 83

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

master

r00

master

r00

origin/master

m00

“Remote Control”

• Next move obviously, is going opposite way

• At this point all tools are set.• ‘git push’ will do the trick.

Introduction to Github 84

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

master

r00

master

r00

origin/master

m00

*Push will commit to the remote tracker, then sync it to the branch on the remote by uploading/overwriting contents.**Again, conflicts can happen here, and your push sometimes ‘rejected’ by the remote. If so, you need to fetch & merge.

r01

‘git push’!!

r01

“Remote Control”

• So, in summary:

• Pull (fetch & merge). Remote tracker created. (Do work.) Push. Done. Let’s do this ->

Introduction to Github 85

Github

Your Eclipse

Remote RepositoryLocal Repository

Your Machine

Index-File1-File2-…

Index-…-…-…

c00

master

r00

master

r00

origin/master

m00

r01r01

Remote Configuration

Introduction to Github 86

Back to Web Browsers.Your Remote Repo page.

Remote Configuration

Introduction to Github 87

Back to Web Browsers.Your Remote Repo page.

Copy this address.Make sure its ‘SSH’.

*You registered SSH key, so you can pull/push via SSH connection.**You can pull via HTTPS, but cannot push.

Remote Configuration

Introduction to Github 88

Remote Configuration

Introduction to Github 89

In the Repo Pane, under the repo> “ リモート” (Remote)

Remote Configuration

Introduction to Github 90

Right click> “ リモートの作成” (Create a remote)

In the Repo Pane, under the repo> “ リモート” (Remote)

Remote Configuration

• Making push configuration first would be a little easier.

Introduction to Github 91

Push Configuration

Introduction to Github 92

Click this to expand

Push Configuration

Introduction to Github 93

PushConfiguration

Introduction to Github 94

Your copied address should automatically be inserted from clipboard.

No need to modify username/password.‘git’ is global username, auth’ed by key

Push Configuration

Introduction to Github 95

Push Configuration

Introduction to Github 96

What was HEAD? > Reference to current branch.

Click & focus here, then hit Ctrl+Space

Push Configuration

Introduction to Github 97

Complement service will automatically search existing remote branches.Choose ‘master’ branch.

Push Configuration

Introduction to Github 98

Checking this has literal meaning.When pushing, it will ignore push rejection from the remote branch and forcibly push the local HEAD.Generally a bad idea.

Push Configuration

Introduction to Github 99

Push Configuration

Introduction to Github 100

• Repositories Pane should now be like this.

Push Configuration

Introduction to Github 101

• Repositories Pane should now be like this.• Right click on ‘origin’• “ フェッチの構成” (Configure fetch)

Fetch Configuration

Introduction to Github 102

Fetch Configuration

Introduction to Github 103

Exactly the same as push

Fetch Configuration

Introduction to Github 104

Fetch Configuration

Introduction to Github 105

Again, click & focus here, then hit Ctrl+Space.Choose ‘master’.

Fetch Configuration

Introduction to Github 106

Another overwrite option.Better not check.

Fetch Configuration

Introduction to Github 107

Now that fetch configuration is ready, let’s try fetching for the first time!Remember, first fetch will create the remote tracking branch ‘origin/master’

Fetch

Introduction to Github 108

Result should be like this.

Server certification acceptance may be prompted.

Remote Tracking Branch

• Under “ ブランチ” (Branch)>” リモート・トラッキング” (Remote tracking), you will find ‘origin/master’

• To reflect the remote status to local…

Introduction to Github 109

Merge

• Right click on the remote tracker• “ マージ” (Merge)

Introduction to Github 110

Merge

• At this time, result should be like this.• Key is ‘Fast-forward’(FF)– Basically means no conflicts there.– To be precise, one branch is wholly older, and its

recent commit is included in the other.

Introduction to Github 111

Merge

• Here comes README from the remote joining the local.

• Finally, to upload this merged commit to the remote…

Introduction to Github 112

Push

Introduction to Github 113

2 ways of doing this:

Right click on the project> “ チーム” (Team)>” アップストリームへプッシュ” (Push to upstream)

orRight click on ‘origin’ under “ リモート”>” プッシュ” (Push)

Push

Introduction to Github 114

• Result should be like this.• At this time no rejection for sure.

Check on Github

Introduction to Github 115

Back to Web Browsers.Try refresh.

Check on Github

Introduction to Github 116

Happy face

Easier way for daily use

• Now the very basic git usage is covered.• May pull / commit and push as shortcut.

Introduction to Github 117

Versioning

• Versioning is done through tagging in git.• You may noticed “ タグ” (Tag) in the repo

pane.• Right click and “ タグの作成” (Create a tag)

Introduction to Github 118

Tag

Introduction to Github 119

Hit this to expand

Tag

Introduction to Github 120

Appropriate name (such as v1.0, v2.4-beta)

Description message

Choose a commit you want to tag

Tag

• Now that commits are tagged.• If you want to publish these tags (versions),

you need to push tags manually.– Not tied to branch pushing, but the concept is

exactly the same.

Introduction to Github 121

Push Tag

• Right click on the tag > “Push Tag”• “ 構成済みレポジトリー”

(Configured Repository)• Hit Next

Introduction to Github 122

Push Tag

• Tricky part: Tags are referred like ‘refs/tags/<tag name>’.

Introduction to Github 123

Push Tag

• Tricky part: Tags are referred like ‘refs/tags/<tag name>’.

• You need to manually specify this.

Introduction to Github 124

Target name

Push Tag

• Tricky part: Tags are referred like ‘refs/tags/<tag name>’.

• You need to manually specify this.

• Basically just copy the name above.

Introduction to Github 125

Target name (refs/tags/v1.1)

Push Tag

• Result should be like the left• On Github, ‘releases’ should appear and you

can see the version history

Introduction to Github 126

Versioning

• Versioning itself needs its own philosophy and practice, and it’s ultimately depends on how the team will handle the project.

• Make/follow the guideline and decide when/how often/what kind of state to publish.

Introduction to Github 127

From Remote, Comes…

• So far, we assumed you have your local project developed without using git.

• And how to integrate it with git is covered.

• Let’s see how to duplicate your git-integrated project to your extra machines.

• Or to duplicate other’s project.– These are done with exact same procedure.

Introduction to Github 128

Clone

• You can ‘git clone’ the remote repo itself.

Introduction to Github 129

Github

Your Eclipse

Remote Repository

Your MachineIndex-…-…-… r00

master

r01

Clone

• You can ‘git clone’ the remote repo itself.

• And it’s really easy!• Not only it copies contents of

the repo, it automatically set all the remote configuration!

Introduction to Github 130

Github

Your Eclipse

Remote Repository

Your MachineIndex-…-…-… r00

master

r01

Local Repository

Index-File1-File2-…

c00

master

r00

origin/master

m00

r01

‘git clone’!!Created!

Created!

Created!

Created!

Clone

• All you need is…

• Copy.

Introduction to Github 131

This.

Clone

• On your target machine,• Right click on the blank area of the repo pane.• “ リポジトリー・パスまたは URI の貼り付け”

Introduction to Github 132

Clone

Introduction to Github 133

Same as before.

Clone

Introduction to Github 134

You cannot clone to non-empty path.

If the repo includes Java project, you can also import them.

Clone

• With cloning, you can duplicate your Eclipse project env. on another machine with ease.– As long as you respect the procedure of

pull/modify/commit/push, you can work on your project from various places without an issue.

– But sometimes an error will happen. And in a team development conflicts are common.• To prevent your working branch being overwritten by a

problematic commit, there is no auto-pull.• To prevent not-ready code being sent to the remote, there is

no auto-commit/push.

Introduction to Github 135

Clone/Fork

• You can clone other developer’s repository, and modify on branches as you like.– You may do this on Github alone, creating the remote

clone of the original in your account. (Called forking.)– Note: However, pushing to original repository is only

allowed to the repo’s owners.• If you have done valuable modification to the branch of

cloned/forked repo, you can ‘pull request’ to the owner.• Push your branch to forked repo, then submit pull request

on the original repo.

Introduction to Github 136

.gitignore

• Sometimes you want certain files to stay untracked/excluded from index.– Especially data including privacy info.

• Then you can “ 無視” (ignore) such data.– Listed on .gitignore

• After that, commit thebranch– .gitignore will be added

Introduction to Github 137

Back to the Past

• So how to return to previous state?• 1-step back (just want to discard 1 commit):– Already pushed? > git revert. Making new commit.

• But your code may already be used by someone.– Not pushed? > Amend commit, or reset and start over.

• Multi-step back– Make new branch on the past commit, checkout (means

moving your current branch(HEAD)), work on it, eventually merge with master, or discard old master and name the current as new master.

– Branching is has high flexibility.

Introduction to Github 138

Other stuff

• There are many more functions in git– Notably rebase.

• But for now, that’s it!– For personal/laboratory use, we learned more

than enough I believe.

• Utilize my account(/YuMatsuzawa/) for testing

Introduction to Github 139

CUI (Git for Windows required)

• $ cd <project directory>• $ git init #repo created• $ git add <files to be added>• $ git commit –a #commit all• $ git remote add origin <remote URI>

#remote config• $ git fetch origin #fetch any branches• $ git merge origin/master #merge remote tracker• $ git push origin master #push to remote

Introduction to Github 140

top related