Brief tutorial on Git

Download Brief tutorial on Git

Post on 06-Jan-2017

3.070 views

Category:

Engineering

1 download

Embed Size (px)

TRANSCRIPT

<ul><li><p>Brief tutorial on Git</p><p>Colin Cheng ( )Shengwen1997.tw@gmail.com</p><p>NCTU Robotic Vision class</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>What is Git?</p><p> A version control system for project management Create by Linux's author Linus Torvalds</p></li><li><p>Before you start using version control system ...</p><p>I think I can manage my project very well </p><p> without git</p><p>code_2016_1_1</p></li><li><p>Before you start using version control system ...</p><p>I think I can manage my project very well </p><p> without git</p><p>code_2016_1_1 code_2016_1_3</p></li><li><p>Before you start using version control system ...</p><p>I think I can manage my project very well </p><p> without git</p><p>code_2016_1_1 code_2016_1_3 code_2016_2_4</p></li><li><p>Before you start using version control system ...</p><p>Help!</p><p>Dude</p></li><li><p>Before you start using version control system ...</p><p>Help!</p><p>Dude</p><p>Inefficient!</p></li><li><p>Also, if the source code size is too big...</p><p>My source code size is approximately 6GB</p></li><li><p>Great! Now you know whywe need to learn Git</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>Example</p><p>Copy the link</p><p>https://github.com/duckietown/software</p></li><li><p>Git clone</p><p>cd ~git clone https://github.com/duckietown/software.gitcd Software/ls</p><p>Whereever you want to store the code, ~ means the home directory</p><p>Clone command</p><p>https://github.com/duckietown/software.git</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>Git init</p><p>Suppose you have a project called duckie,you have to git init the directory once beforeusing the git</p></li><li><p>Git init</p><p>cd ~mkdir duckiecd duckie/git initls -a</p><p>Create new directory called duckie</p><p>Init the project with git</p><p>List all the files including the hidden file</p><p>Git stores all the informations, configurations in this floder</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>Setup your git user informationgit config --global user.name "user name"git config --global user.email "email address"</p></li><li><p>Modify the file</p><p>Now, we are going to modify the file, and usegit to help us store the changes (track).</p><p>We will use vim editor, but if you are not yet familiar with vim, you could try gedit (or Sublime)</p><p>However, I still hope you know how to use vim</p></li><li><p>Create the file as follow</p><p>file: duckie/hello.txt</p><p>Hello World </p></li><li><p>Git status</p><p>git status See the change in this project directory</p><p>Git found we have a new file, but not tracking yet</p></li><li><p>Git add</p><p>git add hello.txt Store the new modification</p></li><li><p>Commit</p><p>After you add all the files (if you have multiple files to add), you can commit all the changes toa single log</p></li><li><p>Git commit</p><p>Git commit -m Create new file Commit description should be brief and easyto understand!</p></li><li><p>So...</p></li><li><p>Please...</p><p>Please do not git add the *.exe file,log file, etc</p><p>Git should only track the source file!</p></li><li><p>Hide the file you don't want git to track</p><p>For example:</p><p>'</p></li><li><p>Create .gitignore</p><p>You can create a .gitignore file at your projectroot directory and list the file you dont want git to track</p><p>file: duckie/.gitignore</p><p>*.exe</p><p>Yes, you can use the regular expression!</p></li><li><p>Hide the file you dont want to track</p><p>See:</p><p>Disappear below</p></li><li><p>See the changes log</p><p>Now, we will like to see all the changes, We can use the program tig</p><p>Type the following command to install it:sudo apt get install tig</p></li><li><p>Check the logtig You will see:</p></li><li><p>MoreType [Enter] to check the log, [q] to leave</p><p>Git will also generate a unique id for every commit(SHA-1), so we can operate the commit by assinging theid (Like invert the commit, etc)</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>Create github repositoryLogin and click the New repository button</p></li><li><p>Create github repository</p></li><li><p>Create github repository</p><p>Actually, you can also learn how tocreate a new git project at here</p></li><li><p>Back to your conslegit remote add origin https://github.com/XXXX/duckie.git </p><p>Check the link on your github repo!</p><p>This command will help you create a remotenamed origin and point to the github repo</p></li><li><p>Git push (Upload)</p><p>Now, you can push your code to your github repo (remote)</p></li><li><p>Git pushGit push origin master</p><p>(git push [REMOTE] [BRANCH]), I will explain what is the branch later</p></li><li><p>Now, refresh your github page!</p></li><li><p>Git pull</p><p>In previous, I taught you how to clone a project,But what if the develper add new features andYou wish to keep your clone up-to-date?</p><p>Now, you need to to use the git pull command</p></li><li><p>Git pullGit pull origin master</p><p>(git pull [REMOTE] [BRANCH])</p><p>Well, this is already up-to-date,try this next time when you need it</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>Branch</p><p>In git, you can create different branches and develop your project at the same time:</p></li><li><p>Merge</p><p>After you finish developing on certin branch, you can merge it back to the master(or other branch)</p><p>This is a merge</p></li><li><p>Head</p><p>Head is the latest commit on your branch,If you are now at the master branch, this isyour Head:</p><p>Head of master</p></li><li><p>Head</p><p>And this will be the Head of the very_nice_feature branch:</p><p>Also a Head</p></li><li><p>Some git branch commands</p><p>git branch new_branch_name Create a new branchgit branch Check current branchgit checkout branch_name Switch to certin branchgit merge branch_name merge certen branch back to the current branch</p><p>*If there is any confict during the merge, git will ask you to fix the the conflicts</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>Fork</p><p>Fork is a Github feature, you can forksomeones project and store it in your githubRepo page</p></li><li><p>ForkClick the buttonhttps://github.com/duckietown/software</p></li><li><p>Fork</p></li><li><p>Outline</p><p>Begin Clone a project from Internet Create a git project Git commit Git push/pull</p><p>Intermediate Branch Fork a project on Github Send a pull request</p></li><li><p>Pull request</p><p>Pull request is also a github feature.</p><p>After you fork the project, you may add more new functions. you can send a pull request to the original author and ask him/her to merge your changes</p><p>Well, the author have the right to merge or not</p></li><li><p>Pull request</p></li><li><p>Pull request</p><p>After you click the button, the Pull request will be sent</p><p>Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Slide 53Slide 54Slide 55Slide 56</p></li></ul>