Git and github introduction


Published on

Git and github introduction

Published in: Software, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Git and github introduction

  1. 1. Git and github introduction Qiang Zhang May 27,2014
  2. 2. ABOUT GIT
  3. 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. 4. 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
  5. 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 "John Smith" >> git config --global "" >> git init # Initialized empty Git repository in /home/ubuntu/myrepo/.git/ >> git status
  6. 6. Edit file and add it into git >> git add file.txt >> git status >> git commit -m "Added first file" >> git log
  7. 7. Main states of git • Git has three main states that your files can reside in: – modified – staged – committed
  8. 8. 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)
  9. 9. 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
  10. 10. 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:
  11. 11. 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
  13. 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. 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. 15. Create repo in github • create repo in github website and push your commit – git remote add origin 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. 16. Build the environment 1. Folk the repository on github website 2. Clone your folk: git clone Knife.git 3. Configure the remote: cd Spoon-Knife git remote add upstream <original repository> git fetch upstream git merge upstream/master
  17. 17. 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
  18. 18. Web resource • step by step guide • Very good tutorial and workflow of git • Git cheatsheet