Git – Introduction – Part II



Git – Introduction – Part II

2 0


Git-Introduction-Part-II


On Github rcos / Git-Introduction-Part-II

Git

Introduction

Part II

Created by Luis Ibanez / @luisibanez and modofoed by Moorthy and @mskmoorthy

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

Complete First

Git-Introduction-Part-I Exercises First

Clone Repository

git clone git@github.com:mskmoorthy/Story.git
  • github username = "mskmoorthy"
  • repository name = "Story"

Go Inside the Directory

cd Story

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 rcosgithub git@github.com:rcos/Story.git
  • rcosgithub = 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 a Branch

git branch Table < i >

git checkout Table < i >

cd Table  < i >

nano table< i >.Md

cd ..

One Team Member

Commits Team Directory

git add table< i > ;.Md

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 rejected

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

All Team Members

Update their local table .Md

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

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

THE END

BY Luis Ibanez

and modified
by Moorthy