git and github simple tutorial
First, create a warehouse
- Click
new
Add to enter the warehouse page
- The warehouse will create some simple settings
- Finally, click
create repository
on it.
- With this we have created a warehouse.
Second, the use git clone, cloned into the local repository
Created on github a warehouse, how it clones (clone) to a local do? This time we need to use git to manage and synchronize. First you need to go to the official website to download git git , then install it. Next we use the git clone command to a local warehouse.
- Using SSH
- Create a workspace in the local git
- Git into the workspace, open a command window git
- Use
git clone
command on the remote repository cloned into local workspace
Format:git clone 刚刚复制的SSH口令
This time we re-open the area to see if it came cloning:
We can see this folder hidden files, see the following steps:
If we want to modify or add a local warehouse of some files, how to update it to the far end? It needs to go through the following three steps:
- Use git add command to commit changes to the work area to the staging area
- Use git commit command to submit modifications to the master branch from scratch
- Use git push command to modify the master branch pushed from the distal end
Third, use git add, modify submitted to the staging area (index or stage)
- First, we need to make some changes to git work area, such as creating a new file
first.txt
- Use the command
git add 文件名
- To which changes have been saved in the staging area, we can use the
git status
command to view the current status
At the same time we can see user "git reset HEAD <file>..." to unstage
, means that we can use this command git reset HEAD 文件名
, just submit the withdrawal. There is no longer a demonstration, interested students can try.
Fourth, use git commit, commit your changes to the local master branch
- The command format is:
git commit -m "对此次提交的简单说明"
,-m
in them
meanmessage
.
- 再次使用
git status
查看当前状态
五、使用git push,将本地修改
- 使用
git push
命令就可以将本地master中的修改提交到远端master中去了。
- 这时候我们刷新github看看
到这,我们已经完成了git的一些基本操作,接下来我们补充一些比较常用的其它git命令。
查看操作git log
,git show commit id
使用git log
命令可以查看我们所有的commit日志
使用git show commit id
命令可以查看一个commit的详细信息
回滚操作git reset commit id
在进行push之前我们可能会进行多次commit操作,有时候我们希望能够退回到某一次commit时的状态,这时我们可以使用git reset commit id
命令。
但请注意,push完之后再reset是没用的,reset只对本地有效!
拉取操作git pull
有时候远端修改领先与我们的本地修改,因为一个仓库可能有多人同时在修改更新,如下图所示:
这时候我们就需要使用git pull
命令来拉取远端的最新状态,同步到本地。
好的,这就是这篇文章的所有内容了,有问题欢迎留言。