本文已参与「新人创作礼活动」,一起开启掘金创作之路。
Git是目前世界上最先进的分布式版本控制系统。
一、Git Workflow
1.git init:creates a new Git repository
2.git status:inspects the contents of the working directory and staging area
3.git add:adds files from the working directory to the staging area
4.git diff:shows the different between the working directory and the staging area
5.git commit:permanently stores file changes from the staging area in the repository
6.git log:shows a list of all previous commits
二、3 different ways to backtrack
1.git checkout HEAD filename:Discards changes in the working directory.
2.git reset HEAD filename:Unstages file changes in the staging area.
3.git reset SHA:Can be used to reset to a previous commit in your commit history.
三、Git Branching
1.git branch:Lists all a Git project's branches
2.git branch branch_name:Creates a new branch
3.git checkout branch_name:Used to switch from one branch to another
4.git merge branch_name:Used to join file changes from one branch to another
5.git branch -d branch_name:Deletes the branch specified
四、Git Teamwork
1.git clone:Creates a local copy of a remote
2.git remote -v:Lists a Git project's remote
3.git fetch:Fetches work from the remote into the local copy.
4.git merge origin/master:Merges origin/master into your local branch.
5.git push origin <branch_name> :Pushes a local branch to the origin remote.
Git projects are usually managed on Github, a website that hosts Git projects for millions of users. With Github you can access your projects from anywhere in the world by using the basic workflow you learned here.
PS:
1.怎么将本地文件上传到github?
- github上创建一个资源
- 切换到你本地目录下
- git init
- git remote add origin xxxx.git //xxx.git就是你在远程github上创建资源http地址
- git add .
- git commit -m 'add'
- git push origin master
- finish
2.如何用git创立自己的项目?
Step 1: Create the README file
In the prompt, type the following code:
mkdir ~/Hello-World
# Creates a directory for your project called "Hello-World" in your user directory
cd ~/Hello-World
# Changes the current working directory to your newly created directory
git init
# Sets up the necessary Git files
# Initialized empty Git repository in /Users/you/Hello-World/.git/
touch README
# Creates a file called "README" in your Hello-World directory
Step 2: Commit your README git add README # Stages your README file, adding it to the list of files to be committed
git commit -m 'first commit'
# Commits your files, adding the message "first commit"
Step 3: Push your commit git remote add origin github.com/username/He…
# Creates a remote named "origin" pointing at your GitHub repository
git push origin master
# Sends your commits in the "master" branch to GitHub
Git和GitHub的相关网站
- Git官网
- GitHub官网
- GitHub Pages:搭建静态网站、博客
Git和GitHub的学习资料
- Git-Book:Git 官方教程中文版
- Git教程:廖雪峰老师写的入门教程,建议入手
- Git权威指南:很经典也很全面,学习git,看这本就够了。
- Github-Help:Github官方的帮助文档
- GotGitHub:和《Git权威指南》是同一个作者,这是国人写的良心之作啊!
好了,关于Git和GitHub的资料就给这么多吧,资料这个东西,贵精不贵多,博主推荐的都是精品,请读者朋友好好研读吧,必定会获益匪浅!在今后有相关的新技术,博主会在第一时间告诉大家,请继续关注博主哟!