Git Demo
Git 由 Linus Torvalds 为管理 Linux 内核源代码而设计。Git 作为分布式的版本控制系统,是国内外互联网开发团队现今所使用的主要版本控制方式。
- Installation Git For Windows
- Installation Text Editor
- The Git Commands
- Use Git with Github
- Create a New Repository Locally
- Add Git to an Existing Project
Installation Git For Windows
1. Download
Open Git for windows, click download button show in your new page,choose the right version of package to download.
For example: I choose Git-2.16.3-64-bit.exe
to download for my Win10 64bit System.
2. Install
Blow are some recommend choices for installing Git for windows. (Feel free to make other choice for yourself.)
Double click the package you have download last step
Next
Next
Use Visual Studio Code as Git’s defult editor
Use Git from the Windows Command Prompt
Use the OpenSSL library
Checkout as-is,commit Unix-style line endings
Use MinTTY(the defult MSYS2)
Next
3. Verify
open Git Bash from start menue
type git version
after $
, then press enter key.
If you Git Bash screen show like blow:
1 | $ git version |
You have installed it right.
Installation Text Editor
Here are several widely used text editors,choose one you prefer to download.
The Git Commands
Basic Concepts
In Git Bash,here are some basic concepts:
~ = Home Directory
pwd = Present Working Directory
/c/ = C:\
1 | $ pwd |
The command-line above:ls
:used to list the files and folders in current directory.ls -l
:used to list the files and folders in current directory with even more details.
Change Directory
1 | pwd |
The command-line above all need to run after ~
in Git Bash.cd Videos/
: change directory to ~Videos.cd ..
: back up one directory level.cd My\ Documents/
: In Git Bash, you have to specify a backslash to escape the space charactor.cd ../../..
: back up three directory level.cd ~
: quickly back to user’s home directory.cd
: the same as cd ~
cd /c/Windows/System32/
: change directory to System32 folder.
Where is that command?
1 | which ls |
which ls
: tells us the location of the ls command.
Echo…Echo
1 | echo "Hello World" |
echo "Hello World"
: echo out string “Hello World”.echo $PATH
: output the value of PATH
variable.echo "The current path is $PATH"
: variable interpolation, combine above two step.
Reviewing Files Contents
Click the link test.txt and you will open it in the new page -> right-click on the page or use the shortcut key ctrl + s -> save it as “test.txt”.
1 | cat test.txt |
cat test.txt
: review the file contents in a raw way.
less test.txt
: review the file contents in a samrt way, input q
then enter key to quit the review.
Create, Rename, and Delete Files
1 | pwd |
Create and Delete Folders
1 | pwd |
mkdir -p projects/client-a/awesome-web-project
: -p: if necessary, create parents directory.rm -rf projects/
: -r: recursive, -f: force.
Clear and Exit
1 | ls -l |
Output to a File
Send the output of a command into a file:
>>
: either create a new file or append to an existing file.>
: override the file, replace the contents entirely.
1 | pwd |
Creating and Executing a Simple Bash Script
1 | pwd |
Customizing the Bash Environment
1 | notepad++ .bashrc # rc: Resource configuration; |
set up aliases, wirte the flowing code in .bashrc
above
1 | alias ll='ls -al' |
Use Git with Github
Key Concepts
- Repository contains files, history, config managed by Git.
- Three States of Git:
- Working directory
- Staging area - pre-commit holding area
- Commit - Git Repository(history)
- Remote repository(Github)
- Master branch
git status
: monitor changes between four status.Staging area
: Git index, a holding area for queuing up changes for the next commit, files haven’t been commited.
Setup The Project Folder
1 | mkdir projects |
Git Configuration
Two bits of information:the name
, email address
.
1 | git version |
Copy the Repository (clone)
1 | # paste in your GitHub HTTPS clone URL |
The First Commit
1 | echo "Test Git Quick Start demo" >> start.txt |
Publishing Changes to GitHub (push)
1 | git push origin master |
Create a New Repository Locally
1 | cd projects |
remove the local repository:
1 | cd ~/projects |
Add Git to an Existing Project
Click the link: initializr-verekia-4.0.zip, cilck the download button in the new page to download it.
1 | pwd |
if .git
is no longer there,this project would no longer be managed by Git.
1 | ls -al |