Git – Introduction – Part II



Git – Introduction – Part II

5 2


Git-Introduction-Part-II

Introduction to Git remote repositories and collaboration

On Github SUNY-Albany-CCI / Git-Introduction-Part-II

Git

Introduction

Part II

Created by Luis Ibanez / @luisibanez

Git Introduction by Luis Ibanez is licensed under a Creative Commons Attribution 3.0 Unported License.

Complete First

Introduction Part I

Clone Repository

git clone git@github.com:ossp/Git-Branchy-Story-Exercise-02.git
          
  • github username = "ossp"
  • repository name = "Branchy-Story-Exercise-02"

Go Inside the Directory

cd Branchy-Story-Exercise-02
          

See the remote repositories

git remote -v
          
  • "-v" is for "verbose"

At this point we have a

Shared Repository

Courtesy of git-scm Book.

This configuration

is used for a

Centralized Workflow

Git enables

other configurations...

to support

other workflows...

For example

Integration Manager Workflow

Courtesy of git-scm Book.

Let's do this !

You already have

local private

repositories

Let's create

your public

repositories

We do this

by forking

in Github

Fork the Repository

Copy the Fork Address

Now go to your

local private

repository

Add the Remote repository

git remote add luisgithub git@github.com:luisibanez/Git-Branchy-Story-Exercise-02.git
          
  • luisgithub = local name for remote repository

See the remote repositories

git remote -v
          

Your Turn !

Add Remote

Repositories

Work with your Team

  • Ask team members for their fork address
  • Add their address as a remote
  • Name the remotes after their first names

Use HTTPS

For the address of your team mates

  • Use:
  • https://github.com/aaronsw/...
  • instead of
  • git@github.com:aaronsw/...

Now let's create

a team directory

to work together

One Team Member

Creates Team Directory

mkdir FantasticFour

cd FantasticFour

nano README.md

cd ..
          

One Team Member

Commits Team Directory

git add FantasticFour

git commit -m "Started team directory"
          

and push it upstream

git push origin master
          

Your push may fail...

with a message like this

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:ossp/Git-Branchy-Story-Exercise-01.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
          

Your push may fail...

with a message like this

This just means

than someone else

pushed before you

so now

you have to update

your local repository

Update With the Command

git pull origin master
          

and then try again the Command

git push origin master
          

You may have

to do it

multiple times

Breath!

Smile!

All Team Members

Update their local repositories

git pull origin master
          

All Team Members

Look at recent commits

git log
          

Note That

The log tells you:

  • Who did it
  • When it was done

All Team Members

Look at recent commits

Using short format

git log --oneline
          

Note That

Every commit

is identified by a hash

such as:

5d7d137a3592fe402a4bc282375c2d8bb878326c
          

You can use

the first characters

to refer

to this commit

You can use

"git show"

git show 5d7d137
          

to find out more

about this commit

See commit details

git show 5d7d137
          

Time to

Go Wild!

Each Team Member

  • Picks a "character" name
  • Go into the team directory
  • Creates a file with that name
  • and extension ".md"

Each Team Member

  • Inside the file write one sentence
  • Describing the state of the character

Each Team Member

  • Git add the file
  • Git commit
  • Git push upstream

Your push may fail...

with a message like this

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:ossp/Git-Branchy-Story-Exercise-01.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
          

This just means

than someone else

pushed before you

so now

you have to update

your local repository

Update With the Command

git pull origin master
          

and then try again the Command

git push origin master
          

You may have

to do it

multiple times

Each Team Member

  • Edit the file of her/his character
  • Change the state of the character

Each Team Member

  • Git create branch
  • Git select branch
  • Git add
  • Git commit into branch

Use the Commands

git branch MyNewBranch
git checkout MyNewBranch
vim myCharacter.md
git add myCharacter.md
git commit
          

The commit message

Must explain "how" and "why"

the character changed state

Each Team Member

  • Git move to master branch
  • Git update master from upstream
  • Git merge branch into master
  • Git push master upstream

Use the Commands

git checkout master
git pull origin master
git merge --no-ff MyNewBranch
git push origin master
          

Reading the Story

as the story grows

you can read it

by using the command:

git  log  --no-merges   .
          

This will show you

what happened

to all the characters

in that directory

To read the Story

of a single character

use the command:

git  log  --no-merges   myCharacter.md
          

To read the summary

of the story

use the command:

git  log  --no-merges   myCharacter.md --oneline
          

You can see the Graph

with the command

git log  --graph
          

You can see the Graph

with the tool gitk

gitk
          

Your Turn !

Unleash your imagination!

Coordinate

with your team mates

  • Interactions between your characters
  • Apply the state changes to your files
  • Git commit, add, merge, every time
  • Read the story as it progresses

Complete Five

Interactions

per character

Breath!

Smile!

THE END

BY Luis Ibanez