Git and github introduction
Upcoming SlideShare
Loading in...5
×
 

Git and github introduction

on

  • 82 views

Git and github introduction

Git and github introduction

Statistics

Views

Total Views
82
Views on SlideShare
81
Embed Views
1

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 1

http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Git and github introduction Git and github introduction Presentation Transcript

  • Git and github introduction Qiang Zhang May 27,2014
  • ABOUT GIT
  • what is git? • git is CVS tool. • The major difference between git and other CVS: if files have not changed, Git doesn’t store the file again—just a link to the previous identical file View slide
  • Features • Nearly Every Operation Is Local • Git has three main states that your files can reside in: committed, modified, and staged. • Folk and pull model View slide
  • An “hello world” example of git • Install and intialize an empty git repo >> sudo apt-get install -y git-core >> mkdir myrepo >> cd myrepo >> git config --global user.name "John Smith" >> git config --global user.email "example@stanford.edu" >> git init # Initialized empty Git repository in /home/ubuntu/myrepo/.git/ >> git status
  • Edit file and add it into git >> git add file.txt >> git status >> git commit -m "Added first file" >> git log
  • Main states of git • Git has three main states that your files can reside in: – modified – staged – committed
  • state: modified • Modified means that you have changed the file but have not committed it to your database yet • For example: you use vim open file.txt and add “hello, world” string. So file.txt is in modified state. • related commands: git checkout -- <filename> (undo the modification)
  • state: staged • Staged means mark a modified file which will go into your next commit. – If it’s modified and added to the staging area(git add file.txt), it is staged. – Otherwise, it is modified. • Related commands: git add, git diff --staged, git reset, git rm
  • state committed • Committed means that the data is safely stored in your local database. • So git can trace all those changes. • For example >> git commit -m "Added first file“ Related commands:
  • Whole flow: Edit another file and add to git Edit your file locally git status git diff file.txt git add file.txt git commit -m "Added a new line to the file." Command help output the committed logs git log git log -p git log -p --color
  • CONTRIBUTE TO A PROJECT WITH GITHUB
  • What is push ? • When you have your project at a point that you want to share, you have to push it upstream. • Command: git push [remote-name] [branch- name] • For example: git push -u origin master push local change to origin repo. The -u tells Git to remember the parameters, so that next time we can simply run git push
  • What is pull ? • git-pull - Fetch from and integrate with another repository or a local branch • In its default mode: git pull = git fetch + git merge FETCH_HEAD For example • git pull origin master Fetch the specified remote’s copy of the current branch and immediately merge it into the local copy.
  • Create repo in github • create repo in github website and push your commit – git remote add origin https://github.com/username/Hello- World.git # Creates a remote named "origin" pointing at your GitHub repository – git push origin master # Sends your commits in the "master" branch to GitHub origin
  • Build the environment 1. Folk the repository on github website 2. Clone your folk: git clone https://github.com/username/Spoon- Knife.git 3. Configure the remote: cd Spoon-Knife git remote add upstream <original repository> git fetch upstream git merge upstream/master
  • first successful bugfix and merge 1. Create the branch and switch to this branch git branch Issue2020 git checkout Issue2020 2. Make change at your branch: git status git add <file name> git commit -m “comments” 3. Switch to master repo and merge code 1. git checkout master 2. git merge Issue2020 3. git branch -d Issue2020 #delete Issue 2020 repo 4. Push your change back to github: git push origin master
  • Web resource • https://try.github.io step by step guide • https://www.atlassian.com/git/ Very good tutorial and workflow of git • Git cheatsheet