Git & GitHub

Shubham Patel

GDG Coimbatore DevFest 2016

The presentation is to be/was accompanied by demos.

The flow of the presentation is unconventional and is driven by questions - What is needed and How you can accomplish it using Git and Github.

Agenda

  • Local Development
  • Collaboration
  • GitHub features
  • Git Deep Dive (time permissible)
  • (Some) External Integration
    • Slack
    • Trello

Local Development

Why do you maintain a software Project?

backtracking, collaboration, work log

How do you maintain a software Project?

Version control (Git, SVN, Mercurial, etc.)

Init(ialize) the version control (git) for your project

git init

Clone someone else’s project?

git clone path_to_directory

You use domain or username:ip

Files: Untracked, Modified, Staged

git status

What changes have I made recently?

git diff

Save the diff to a file

git diff > changes.patch

Apply a patch

git apply changes.patch

What differentiates 2 versions of a Software?

Finalized changes (= Additions and Deletions)

Commits

Who finalized this changes?

git config user.name “Your Name”

git config user.email “Your email”

After changing 2 files, how to release a new version?

git add file_name

git add *

git commit

So git remove is opposite of add?

Yes! But No.

It stages the file which is deleted.

And, it’s git rm.

How do I finalize the changes made?

git commit

How I should convey what changes I have made?

git commit -m “Your message here”

Change last commit

git commit --amend

List all commits

git log

What changes I did in that commit?

git show commit_hash

How to implement multiple features at the same time?

Branches

Commit 1

Commit 2

Commit 3

Commit 6

Commit 4

Commit 5

user_authentication

new_db_migrations

Creating a new branch

from current branch: git checkout -b new_branch

from another branch: git checkout -b new_branch another_branch

Deleting a new branch

git branch -d branch_name

How to change current branch?

git checkout branch_name

List of all the branches?

git branch

So checkout is used only to change branches?

No. To jump to a specific version of software.

git checkout commit_hash

git checkout file_name (caution!)

How to merge the changes of other_branch into the active branch?

without preserving history: git merge other_branch

with merge history: git merge --no-ff other_branch

What can go wrong while merging?

Changes at the exact place.

Need to resolve the conflict.

This is irrespective of whether you have staged or not.

So, I cannot change the branch without committing?

git stash

git stash apply

Another option for merging

git rebase

So, there’s nothing new in rebase?

git rebase -i

for squashing and editing

Undo the last N commit(s), but preserve the changes

git reset --soft HEAD~N

I wasted my time. Undo last N commits completely

git reset --hard HEAD~N

Remove the file from the

staging (index)

git reset file

So, what did we cover till now?

  • init
  • clone
  • status
  • diff
  • add
  • rm
  • commit
  • log
  • show
  • checkout
  • stash
  • branch
  • rebase
  • reset
  • revert

Reference: http://blog.osteele.com/posts/2008/05/my-git-workflow/

Collaboration

What connects the local repo to the ‘remote’ repo?

git remote add/add/remove remote_name

‘Push’ your changes to specific remote branch

git push remote_name branch_name

What can go wrong while pushing?

You still don’t have the changes pushed made by a friend.

Fetching all the new objects

git fetch remote_name branch_name

‘Pull’ your changes from specific remote branch

git pull remote_name branch_name

pull = fetch + merge

GitHub: Features

  • Repositories
  • Forking
  • Pull requests
  • Issues
  • Milestone tracking
  • Story boards
  • Trending

Some awesome Projects

Git Deep Dive

Agenda

  • How to produce the blobs?
  • What are tree?
  • How to write the trees?
  • How Git commits?
  • How are Hashes produced?

How are hashes produced?

Ruby code:

  • content = “Hello world!”
  • header = “blob #{ content.length }\0”
  • hash = Digest::SHA1.hexdigest ( header + content )

Resources

Thanks!!

Q&A

Git & GitHub Interactive - Google Slides