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