Git + Github

 

Speakers

Quick Poll

  • What is source code?
  • What is open source?
  • Who has used git?
  • Who has used github?

Open Source?

  • Source code is available to play with, modify it and can be distributed generally.
  • It can be free or not.

You told me source code is available to play with but where I will get the source code.

Wait a second!

Github is one of the place on Internet where you can get source code of various famous open source projects like Django, vlc, AngularJS.

What is Git?

Git is a version control system(VCS) which is a tool to manage the history of our Source Code.

What is Version control system?

It is having infinite versions of the same file say testing.txt

Time for a Demo

Need 5 volunteers

Can you give us an example?

Yes.

  • It is like the parent of your code. Just like your parents know about the changes in your life. Git knows the changes happened in the life of code. Your life can not be reverted but git can go the past if something wrong happens.

 

  • It takes a snapshot of the code in the history of Project. So if things goes wrong, you can revert back to the most recent working version.

What is Github?

Github is a place to store your git projects online.

 

It is a social network for nerds Developers.

Github allows you to work in a Team

Github allows to

  • Get the source code of various open source projects
  • Contribute to these projects.
  • Make your project open source.
  • Work with team to create awesome stuff.
  • Manage different versions of your project.
  • Create an online resume to showcase the projects you own and contributed to.

Review

  • What is Open Source?
  • Git
  • Github

Getting your hands dirty..

Setting up Git

 

 

$ git config --global user.name "YOUR NAME"
  • Tell Git your E-mail                                       
$ git config --global user.email "YOUR EMAIL ADDRESS"

Don't worry. The above set up is to be done only once.

Sign Up on Github

Create a Repository

Repository?

  • Github Repository is a fancy name for folder on Github
  • This folder contains all your project files.

Repository is created

Create a local copy of Github repository

$ git clone https://github.com/Parbhat/sfd-github-workshop.git

It will create a folder in your computer with the same files on github.

Review

  • Setting up git on your computer
  • What is a Repository?
  • How to clone a Github Repository

What's next?

Start working on your project..

Create a new file in your project like sfd.txt

Software Freedom Day is everywhere!
SFD is a yearly celebration for Software Freedom!
Every year there are thousands teams organizing
Software Freedom Day in different
countries and cities.

sfd.txt

Great you have created a new file locally. Now its time to send this file on Github so others can see it.

Now Git will come into picture

 

Git will version control this file named sfd.txt to record the changes happening with file over time.

 Git status

Run git status inside project folder.

puri@puri-PC:~/sfd-github-workshop$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

	sfd.txt

nothing added to commit but untracked files present (use "git add" to track)

 Git add

Run git add for tracking new files.

puri@puri-PC:~/sfd-github-workshop$ git add sfd.txt 

 Git status

Check the status again.

puri@puri-PC:~/sfd-github-workshop$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   sfd.txt

 Git commit

It is a snapshot of your code.

puri@puri-PC:~/sfd-github-workshop$ git commit -m "Created sfd text file"
[master 4bd5ead] Created sfd text file
 1 file changed, 5 insertions(+)
 create mode 100644 sfd.txt

-m = commit message

 Git status

Check the status again.

puri@puri-PC:~/sfd-github-workshop$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

We have created sfd.txt file locally but how to send it to Github

 Git push

Git push send all commits to github.

puri@puri-PC:~/sfd-github-workshop$ git push -u origin master 
Username for 'https://github.com': parbhat
Password for 'https://parbhat@github.com': 
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 414 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/Parbhat/sfd-github-workshop.git
   ab4b147..4bd5ead  master -> master
Branch master set up to track remote branch master from origin.

Now our github looks like

Great you have made your first Open Source contribution.

Review

  • Git status
  • Git add
  • Git commit
  • Git push

Git Mantra

Add

Commit

Push

Check the status often.

Learn More

these are the basics

Demo Time

Contributing to projects on Github

Find a project that interests you and fork it

Fork?

It is creating a copy of project to your account.

Original Project

Forked Project

This is your copy of the project. Modify it as you like and follow the Git Mantra.

Remember the Git Mantra..

You have made some awesome changes in the project

What's next?

Open a Pull Request

With Pull request you are asking the maintainer of project to add your changes to the main project.

Give your Pull request a name and description

Maintainer will check the changes and merge it if its correct

Awesome! You are now an Open Source Contributor.

Review

  • Fork a project
  • Follow Git Mantra
  • Open a Pull Request

Git beyond basics

  • git rebase
  • git merge 
  • git stash
  • git reset
  • solve git conflicts

The best way to learn git is to work on projects with a team and witness the awesomeness yourself.

Learning Resources

Any Questions?

Thank You

SFD Github Workshop

By Parbhat Puri

SFD Github Workshop

Slides for Github workshop in Software Freedom Day 2015.

  • 2,913