getting with git

37
Getting with GIT December 13, 2014 Moyinoluwa ADEYEMI

Upload: moyinoluwa-adeyemi

Post on 12-Jul-2015

213 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Getting with GIT

Getting with GITDecember 13, 2014

Moyinoluwa ADEYEMI

Page 2: Getting with GIT

Outline

Outline

• Introduction (i)

• Getting Started (i)

• Introduction (ii)

• Getting Started (ii)

• Introduction (iii)

Page 3: Getting with GIT

Introduction (i)

Page 4: Getting with GIT

Introduction (i)

Let’s play a little game called Imagine.Shall we?

Page 5: Getting with GIT

Introduction (i)

What is Version Control?

Page 6: Getting with GIT

Introduction (i)

Why use a Version Control System?

• Collaboration

• Storing versions properly

• Restoring previous versions

• Understanding what happened

• Backup

Page 7: Getting with GIT

Introduction (i)

Types of Version Control Systems

• Centralized Version Control System (CVCS)e.g. Subversion

• Distributed Version Control System (DVCS)e.g. Git

Page 8: Getting with GIT

Introduction (i)

Why Git?

• Save time

• Work offline

• Undo mistakes

• Make useful commits

• Work in your own way

• Don’t mix things up

Page 9: Getting with GIT

Getting Started (i)

Page 10: Getting with GIT

Getting Started (i)

How to install Git

Installing Git on Windows

• Download the latest version from http://msysgit.github.io/

• When installing, choose the default options in each screen

• Begin work by starting “Git Bash”

Page 11: Getting with GIT

Getting Started (i)

How to install Git

Installing Git on Mac OS X

• Download an installer package from https://code.google.com/p/git-osx-installer/downloads/list?can=3/

• Begin work by starting “Terminal.app”.

Page 12: Getting with GIT

Getting Started (i)

How to install Git

Installing Git on Linux

• On Fedora use:sudo yum install git

• On a Debian-based distribution like Ubuntu, use apt to update your local package index. You can then download and install the program:

sudo apt-get updatesudo apt-get install git

Page 13: Getting with GIT

Getting Started (i)

Configuring Git

• Set your name $ git config --global user.name “Jane Doe”

• Set your email address$ git config --global user.email “[email protected]

• Enable coloring?$ git config --global color.ui auto

Page 14: Getting with GIT

Introduction (ii)

Page 15: Getting with GIT

Introduction (ii)

• RepositoryA place where the history of your work is stored. It lives in a .git folder in

the root directory of your project.

• TypesLocal Repository – Resides on your local computerRemote Repository – Located on a remote server on the internet

Page 16: Getting with GIT

Introduction (ii)

Repository registers

• CloneCreates a “copy” of a repository

• ForkClone a remote repository. Create a copy that you can modify

independently

• StarKeep track of interesting projects

Page 17: Getting with GIT

Introduction (ii)

Repository registers

• Untracked files

• Tracked files

• Working copy

• Staging area

Page 18: Getting with GIT

Introduction (ii)

Page 19: Getting with GIT

Introduction (ii)

Some Git commands

• Init - $ git init

• Add - $ git add -<file>

• Commit - $ git commit -m “Commit message”

• Status - $ git status

• Log - $ git log

Page 20: Getting with GIT

Getting Started (ii)

Page 21: Getting with GIT

Getting Started (ii)

Starting with an unversioned project

• Change into the project’s root folder on the command line.$ cd path/to/project

• Use the “git init” command to version the project. $ git init

Notice the .git subdirectory? To help you understand what’s going on, check the status of your repo ($ git status) after typing any command.

Page 22: Getting with GIT

Getting Started (ii)

Starting with an unversioned project

• Add a file to your project folder. Check the status.

• Use the “git add” command to track this file$ git add gdaysdemo.html

• Use “git commit” to commit the file$ git commit –m “Initial commit”

• Use “git log” to check the changes that happened in the commit$ git log –p

Page 23: Getting with GIT

Getting Started (ii)

Pushing an existing project to GitHub

• Login/Signup to GitHub to create a repo.

• Add remote origin in your local project folder (the same as the last one used)$ git remote add origin https://github.com/<username>/<projectname>.git

• Push to GitHub$ git push –u origin master

Page 24: Getting with GIT

Getting Started (ii)

Starting with an existing project

• Navigate to https://github.com/moyheen

• Clone the gdaysnigeria2014 repo. Make sure that you are in the folder where you want this project to be downloaded to.

• Create a file (please name it with your github username), stage and commit it.

• Use “git push origin” to push the file to the remote repo and use “git log” to monitor your commits.

Page 25: Getting with GIT

Getting Started (ii)

You are the real MVP!

You just learnt the basics of version control with GIT.

(y)

Page 26: Getting with GIT

Introduction (iii)

Page 27: Getting with GIT

Introduction(iii)

• Branches

• Working with branches

• Saving changes temporarily

• Checking out a local branch

• Merging changes

Page 28: Getting with GIT

Introduction(iii)

Branches are the perfect tool to help you avoid mixing up different lines of development.

Page 29: Getting with GIT

Introduction(iii)

Branches gives you the ability to work on different things in parallel, leaving you withat least one context for the “main” or “production” state, and another context for eachfeature.

Page 30: Getting with GIT

Introduction(iii)

Working with branches

• The currently active, or “checked out”, or “HEAD” branch

• Branch master

• Creating a new branch - $ git branch <branchname>

• $ git branch -v

Page 31: Getting with GIT

Introduction(iii)

Saving changes temporarily

• The Stash

• Stashing a local change - $ git stash

• Get an overview of current stashes- $ git stash list

• Restore a saved stash.“git stash pop” will apply the newest stash and clear it from the stash

clipboard.“git stash apply <stashname>” will apply the specified stash but it will

remain saved.

Page 32: Getting with GIT

Introduction(iii)

When to stash

• Before checking out a different branch

• Before pulling remote changes

• Before merging a branch

Page 33: Getting with GIT

Introduction(iii)

• Checking out a local branch$ git checkout <branchname>

• Merging changes$ git merge <branchname>

First checkout the branch that should receive the changesCall “git merge” with the name of the branch that contains the desired changes

Page 34: Getting with GIT

Introduction(iii)

• Merge conflicts

$ git statusOn branch <branchname>You have unmerged paths.

Page 35: Getting with GIT

Introduction(iii)

After solving all conflicts, a merge conflict needs to be concluded by a “git add” (if merge isdone by hand andnot with a merge tool) and a regular commit.

Undoing a Merge with “git merge --abort”

Use “git reset --hard” to roll back to the commit before the merge happened.

Page 36: Getting with GIT

The ebook at http://www.git-tower.com/learn/ebook/command-line aided the preparation of this slide.

Page 37: Getting with GIT

Thank You

Moyinoluwa AdeyemiObafemi Awolowo University

Twitter - @moyheenLinkedIn - ng.linkedin.com/in/moyheen/

Gmail - [email protected]