git命令行提交代码到远程仓库

1.本地建立一个gitdemo的java项目。然后cmd到该项目下面初始化本地仓库

➜  gitdemo git:( master ) git init
Initialized empty Git repository in /Users/xxxx/Documents/workspace/gitdemo/.git/

2.关联远程CSDN仓库(此处设置为https的地址,不需要shh的私钥匙和公钥)

➜  gitdemo git:( master ) git remote add origin https://code.csdn.net/csdn_xxxxx/gitdemo.git

可以通过命令查看设置的git的值

➜  gitdemo git:( master ) git config --list
user.name=csdn_xxxxx
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://code.csdn.net/csdn_xxxxx/gitdemo.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

3.提交文件

➜  gitdemo git:( master ) git add src/com/cy/Demo.java
➜  gitdemo git:( master ) git add src/com/cy/Demo2.java

4.提交完毕commit到私有库

➜  gitdemo git:( master ) git commit -m "first commit"                                      
[master (root-commit) 76179f3] first commit
 2 files changed, 12 insertions(+)
 create mode 100644 src/com/cy/Demo.java
 create mode 100644 src/com/cy/Demo2.java

5.push到CSDN库

➜  gitdemo git:( master ) git push -u origin master                                         
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (7/7), 486 bytes | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)
To https://code.csdn.net/csdn_xxxxx/gitdemo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

6.通过命令查看git私有库的状态

➜  gitdemo git:( master ) git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add ..." to include in what will be committed)

.classpath
.project
.settings/
bin/

nothing added to commit but untracked files present (use "git add" to track)

你可能感兴趣的:(git)