git and github introduction

18
Git and github introduction Qiang Zhang May 27,2014

Upload: john-zhang

Post on 11-May-2015

152 views

Category:

Software


1 download

DESCRIPTION

Git and github introduction

TRANSCRIPT

  • 1.Git and github introduction Qiang Zhang May 27,2014

2. ABOUT GIT 3. what is git? git is CVS tool. The major difference between git and other CVS: if files have not changed, Git doesnt store the file againjust a link to the previous identical file 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. 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 "[email protected]" >> git init # Initialized empty Git repository in /home/ubuntu/myrepo/.git/ >> git status 6. Edit file and add it into git >> git add file.txt >> git status >> git commit -m "Added first file" >> git log 7. Main states of git Git has three main states that your files can reside in: modified staged committed 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 -- (undo the modification) 9. state: staged Staged means mark a modified file which will go into your next commit. If its 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 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. 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 12. CONTRIBUTE TO A PROJECT 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 remotes copy of the current branch and immediately merge it into the local copy. 15. 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 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 git fetch upstream git merge upstream/master 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 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 step by step guide https://www.atlassian.com/git/ Very good tutorial and workflow of git Git cheatsheet