Git常用命令
克隆远程仓库git clone
如下所示,使用git clone 命令时,指定了 项目名称。
Lenovo@LENOVO-PC /e/HelloGit2 (master)
$ git clone git@github.com:hellolyx1618/first-github.git MyDemo
Cloning into 'MyDemo'...
Enter passphrase for key '/c/Users/Lenovo/.ssh/id_rsa':
remote: Counting objects: 23, done.
remote: Total 23 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (23/23), done.
Resolving deltas: 100% (4/4), done.
Checking connectivity... done.
Lenovo@LENOVO-PC /e/HelloGit2 (master)
$ ls
MyDemo
Lenovo@LENOVO-PC /e/HelloGit2 (master)
$
查看文件的状态git status
Lenovo@LENOVO-PC /e/HelloGit2/first-github (master)
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.txt
nothing added to commit but untracked files present (use "git add" to track)
跟踪新文件git add
Lenovo@LENOVO-PC /e/HelloGit2/first-github (master)
$ git add readme.txt
Lenovo@LENOVO-PC /e/HelloGit2/first-github (master)
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: readme.txt
提交文件的更新git commit
Lenovo@LENOVO-PC /e/HelloGit2/first-github (master)
$ git commit -m "test commit readme.txt"
[master (root-commit) f27c6e7] test commit readme.txt
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
Lenovo@LENOVO-PC /e/HelloGit2/first-github (master)
$ git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working directory clean
git pull(git pull [remoteName] [localBranchName])
Lenovo@LENOVO-PC /e/HelloGit2/first-github (master)
$ git pull first-github master
Enter passphrase for key '/c/Users/Lenovo/.ssh/id_rsa':
From github.com:hellolyx1618/first-github
* branch master -> FETCH_HEAD
Already up-to-date.
git push(git push [remoteName] [localBranchName])
将本地commit的代码更新到远程版本库中,例如 “git push origin”就会将本地的代码更新到名为orgin的远程版本库中。
执行git push命令
Lenovo@LENOVO-PC /e/HelloGit2/first-github (master)
$ git push first-github master
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to
he list of known hosts.
Enter passphrase for key '/c/Users/Lenovo/.ssh/id_rsa':
Counting objects: 3, done.
Writing objects: 100% (3/3), 239 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:hellolyx1618/first-github.git
* [new branch] master -> master
=========================END=========================