This document provides an overview of using Git for version control. It begins with cloning a project from the internet and creating a local Git project. It then covers committing changes, pushing commits to a remote repository on GitHub, and pulling updates. The document also discusses branching, forking projects on GitHub, and sending pull requests to contribute changes back to the original project.
Energy Awareness training ppt for manufacturing process.pptx
Brief tutorial on Git
1. Brief tutorial on Git
Colin Cheng ( 鄭聖文 )
Shengwen1997.tw@gmail.com
NCTU Robotic Vision class
2. 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
3. What is Git?
●
A version control system for project management
●
Create by Linux's author Linus Torvalds
4. Before you start using version
control system ...
I think I can manage
my project very well
without git
code_2016_1_1
5. 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
6. 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
11. 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
13. Git clone
cd ~
git clone https://github.com/duckietown/software.git
cd Software/
ls
Whereever you want to store the code, ~ means the home directory
Clone command
14. 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
15. Git init
Suppose you have a project called “duckie”,
you have to git init the directory once before
using the git
16. Git init
cd ~
mkdir duckie
cd duckie/
git init
ls -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
17. 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
18. Setup your git user
information
git config --global user.name "user name"
git config --global user.email "email address"
19. Modify the file
Now, we are going to modify the file, and use
git 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
20. Create the file as
follow
file: duckie/hello.txt
Hello World
21. Git status
git status See the change in this project directory
Git found we have a new file, but not tracking yet
26. Please...
Please do not git add the *.exe file,
log file, etc…
Git should only track the source file!
27. Hide the file you don't
want git to track
For example:
'
28. Create .gitignore
You can create a .gitignore file at your project
root directory and list the file you don’t want
git to track
file: duckie/.gitignore
*.exe
Yes, you can use the regular expression!
29. Hide the file you dont
want to track
See:
Disappear below
30. 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
32. More
Type [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 the
id (Like invert the commit, etc)
33. 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
37. Back to your consle
git remote add origin https://github.com/XXXX/duckie.git
Check the link on your github repo!
This command will help you create a remote
named “origin” and point to the github repo
41. Git pull
In previous, I taught you how to clone a project,
But what if the develper add new features and
You wish to keep your clone up-to-date?
Now, you need to to use the git pull command
42. Git pull
Git pull origin master
(git pull [REMOTE] [BRANCH])
Well, this is already up-to-date,
try this next time when you need it
43. 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
44. Branch
In git, you can create different branches and
develop your project at the same time:
45. Merge
After you finish developing on certin branch,
you can merge it back to the master(or other
branch)
This is a merge
46. Head
Head is the latest commit on your branch,
If you are now at the master branch, this is
your Head:
Head of master
47. Head
And this will be the Head of the
very_nice_feature branch:
Also a Head
48. Some git branch commands
git branch new_branch_name ← Create a new branch
git branch ← Check current branch
git checkout branch_name ← Switch to certin branch
git 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
49. 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
50. Fork
Fork is a Github feature, you can fork
someone’s project and store it in your github
Repo page
53. 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
54. 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