Git + Github

 

Speakers

  • Mohit Kumar Bajoria
  • Iresh Mishra

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 Mess) 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 VLC, AngularJs etc.

 Github?

Github is a place to store your git projects online.

Git + Hub = GitHub

Basically a Social Network of Developers!!

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.

Github allows you to work in a Team

That's COOL!!

BUT..... What the heck is Git??

What the heck is Git?

Git is a Version Control System(VCS) which is a tool to manage the history of our Source Code.

Developed by Linus Torvalds in 2005

What is V.C.S?

It allows you to:-

  • Revert Files to Previous State
  • Revert Entire Projects to Previous State
  • Compare Changes  Over  Time
  • See who modified what...& much more...

A system that records changes to a file or set of files over time so that you can recall specific versions later.

Time for a Demo

Need 5 volunteers

Real Life
 example?

Yes!!

Can You?

  • It is like a Film Shoot. Just like the Director knows about the changes in the Film. Git knows the changes happened in the life of code.
  • Just as the scenes  can be re-shot... git can also go back to 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.

Review

  • What is Open Source?
  • Git
  • Github

Getting your hands dirty..

Sign Up on Github

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.

Create a Repository

Repository?

  •  Repository is a fancy name for online folder which contains all the files within a project
  • GitHub allows any contributor to get notified about any changes in any file within a Repository.

  • A Repository in one account can be copied in another account using "Fork" Button.

  • A new Repository can be created by clicking on the the "+" button in Github Menu bar.

Repository is created

Create a local copy of Github repository

$ git clone https://github.com/mbj36/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.

Some Basic Commands

  • git init
  • cd <address>
  • notepad <filename>

 Git status

Run git status inside project folder.

 Git add

Run git add for tracking new files.

hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ git add  -all

 Git status

Check the status again.

$ 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.

hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ git commit -m"Created Text File"
[master 1977c06] Created Text File
 1 file changed, 5 insertions(+)
 create mode 100644 sfd.txt

-m = commit message

 Git status

Check the status again.


hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ 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 tree clean

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

 Git push

Git push send all commits to github.

hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ git push origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 402 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/mbj36/Github-Workshop.git
   218a38a..1977c06  master -> master

$ git push "Remote Name" "Branch Name"

ex - $ git push origin master

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

Find a project that interests you and fork it

Projects could be found on:-

https://github.com/explore

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.

Maintainer will check the changes and merge it if its correct

Awesome! You are now an Open Source Contributor.

Github Remotes

These are like Variables which have the value as the link to a particular report on Github remote server

$ git remote add upstream "REPO LINK"
$ git remote add upstream "https://github.com/smvdu/sfd-smvdu.git"

Git Fetch

$ git fetch "REMOTE NAME"

$ git merge "REMOTE NAME"/"BRANCH NAME"

"git fetch" gets the latest code from the parent repo and add it directly to your local repo.

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

Learning Resources

Any Questions?

Thank You

SFD - Github

By sfd

SFD - Github

Slides for Github workshop in Software Freedom Day 2016.

  • 1,932