• No results found

Version Control using Git and Github. Joseph Rivera

N/A
N/A
Protected

Academic year: 2021

Share "Version Control using Git and Github. Joseph Rivera"

Copied!
16
0
0

Loading.... (view fulltext now)

Full text

(1)

Version Control

using Git and Github

Joseph Rivera

(2)

What is Version Control?

Powerful development tool!

Management of additions, deletions, and modifications to

software/source code or more generally any documents or

files.

Attempts quality documentation of changes throughout

lifetime of software or document development.

Version Control System

• Usually a standalone application used to keep track of revisions.

• Can be used on servers or with a website (like Github or Wikipedia)

(3)

Why is Version Control Necessary?

Keeps older versions with a history of all changes made.

• If you break something vital, and can’t figure out what you did

• “Roll back” to a working version!

• Compare old implementations vs. new implementations

• See when and why changes were made

Managing multiple users

• What if you want to develop a new functionality?

• Create a “branch” that can be manipulated without affecting the original version!

• When the branch is ready, you can merge it back in, handling any conflicts that may arise.

• Keep track of who made what changes when, and why

(4)

Git ~ The Stupid Content Tracker

A Distributed Version Control System

• Each user has a complete copy of the repository

• Protects against “central” repository failure

• Work on your own without messing up other people’s stuff

• Meritocracy without complete loss of control

Developed by Linus Torvalds (Creator of Linux)

• Initially created for use in Linux Kernel development

• Open Source, so you can learn about version control (and make it better)!

• Primary Goals

• Speed

• Non-linear development support

(5)

GitHub ~ Build software better, together

Online project hosting for Git version control repositories

• Great way to spread open source code.

• Free hosting of public repositories, each up to ~1GB

• Students can get 5 free private repos for 2 years

• Pricing plans for more serious private repos

Why use it?

• Great way to get experience and show off what you can do

• Keep track of statistics about your projects

• Easy access to your repos

(6)

Git ~ Basics

• Install Git using a package manager or build from source

• sudo pacman –S git (Arch Linux)

• sudo apt-get install git-core (Ubuntu)

• Creating a Git repository

• “Clone” an existing repository (remote or local)

• Creating a new repository

• git init

• Set default username and email

• git config --global user.name “John Doe”

• git config --global user.email “[email protected]

• Set default editor

• git config --global core.editor “emacs” • Clone remote repository (using http)

• git clone https://github.com/jrivera777/OpenGL-Asteroids.git

• Clone local repository

• git clone file:////<host>/<share>/<path>

(7)
(8)

Git ~Basics (Cont)

• Add file to be “tracked”

• Tracked files will have changes stored during a commit (called staging), and eventual push.

• git add README.md

• Untracked files will begin being tracked and are staged.

• Stop tracking files • git rm stupidFile

• Forget changes made to file • git checkout -- file.txt

• Commit changes • git commit

• git commit –m “A commit message!”

• If you want to just stage all tracked changes and commit them

• git commit –a

• Not using the –m flag will make a default editor show up asking for

(9)

Git ~Basics (Cont)

Check tracked and staged files

• git status

• Shows all files that are going to be committed (staged files)

• Shows files that have been removed and un-staged

• Shows files that have been modified, but are not staged

Seeing modifications not yet staged

• git diff

(10)

Git ~ Basics (Cont)

Oftentimes after forking a repo, you wish to retrieve any

changes made on that repo

We may also wish to track other people’s forks of the same

project.

Show tracked external repositories

• Note: After a git clone you will have a remote called origin

• git remote

Add new remote tracking

• git remote add upstream [email protected]:PantherLinuxUserGroup/PLUG-Wall.git

(11)

Git ~ Basics (Cont)

Pushing your commits to a remote repository

• Changes the remote repository to reflect all changes made during commits on your local copy

• git push [remote-name] [branch-name]

• git push origin master

• Pushes changes (commits) made in your local master branch to the remote origin branch. Cloning sets up these names automatically.

• If someone else has pushed before you, this command fails (as it should)! Why?

Pulling and incorporating changes from a remote repository

• git pull upstream master

• Attempts to retrieve changes in the master branch of the remote repository named upstream. If conflicts occur with commits you made locally, you can resolve them at this point.

(12)

Git ~ Basics (Cont)

Creating Branches

• You wish to work on new functionality or bug fixes without compromising your stable code base.

• Show existing branches and current branch

• git branch

• Create new branch

• git branch New-Branch • Move into a branch

• git checkout New-Branch

• Create new branch and move into it

• git checkout –b New-Branch

(13)

Git ~ Basics (Cont)

After working on changes or new functionality, we will

eventually be ready to make it part of the primary code base.

If no conflicts occur, all code from one branch is put into

another.

Usually branches are merged into a master branch.

Merging branches

• git checkout master (move into main branch)

• git merge Issue77

• git branch –d Issue77 (delete successfully merged branch)

If conflicts occur, you can use

git status

and

git diff

to make

(14)

Git ~Basics (Cont)

Still not sure about a command?

• git help

• Shows a synopsis of the most commonly used commands

• git help <command> gives details about a particular command

• -a lists all commands

(15)

Github

Many different visualizations of project progression

Issue tracking system

Generate pull requests to add your work to projects you’ve

forked from

Comment system for issues, commits, pull requests, and

more.

Great place to read other people’s code, get ideas, and

explore trending repos

(16)

Resources

Want more information or examples about git and it’s

commands?

Visit:

• http://git-scm.com/book

• http://www.ericsink.com/vcbe/

• https://github.com/

Ask PLUG officers and members!

References

Related documents