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

Git and github introduction

  • 1.
    Git and githubintroduction Qiang Zhang May 27,2014
  • 2.
  • 3.
    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
  • 4.
    Features • Nearly EveryOperation Is Local • Git has three main states that your files can reside in: committed, modified, and staged. • Folk and pull model
  • 5.
    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
  • 6.
    Edit file andadd it into git >> git add file.txt >> git status >> git commit -m "Added first file" >> git log
  • 7.
    Main states ofgit • Git has three main states that your files can reside in: – modified – staged – committed
  • 8.
    state: modified • Modifiedmeans 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)
  • 9.
    state: staged • Stagedmeans 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
  • 10.
    state committed • Committedmeans 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:
  • 11.
    Whole flow: Editanother 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
  • 12.
    CONTRIBUTE TO APROJECT WITH GITHUB
  • 13.
    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
  • 14.
    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.
  • 15.
    Create repo ingithub • 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
  • 16.
    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
  • 17.
    first successful bugfixand 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
  • 18.
    Web resource • https://try.github.io stepby step guide • https://www.atlassian.com/git/ Very good tutorial and workflow of git • Git cheatsheet