如何用命令将本地项目上传到git

1、(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库

git init

 

1.1、配置默认分支:

git config --global init.defaultBranch main

git branch -m main

 

 

2、把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点“.”,意为添加文件夹下的所有文件

git add .

3、用命令 git commit告诉Git,把文件提交到仓库。引号内为提交说明

git commit -m "first commit"

4、关联到远程库

git remote add origin 你的远程库地址

如:

git remote add origin https://github.com/githubusername/demo.git

5、获取远程库与本地同步合并(如果远程库不为空必须做这一步,否则后面的提交会失败)

git pull --rebase origin main

6、把本地库的内容推送到远程,使用 git push命令,实际上是把当前分支master推送到远程。执行此命令后会要求输入用户名、密码,验证通过后即开始上传。

git push -u origin main

*、状态查询命令

git status

 

 

参考 http://www.cnblogs.com/tugenhua0707/p/4050072.html

 

 

从命令行创建一个新的仓库

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin http://ip:port/service.git
git push -u origin master
 

从命令行推送已经创建的仓库

git remote add origin http://ip:port/service.git
git push -u origin master








 

 

 

 

Command line instructions

Git global setup
git config --global user.name "xxx"
git config --global user.email "xxx.xxx@xxx.com"
Create a new repository
git clone http://git.xxx.com/gzszf/xxx-xx-xxx.git
cd xx-xx-cryptohl
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin http://xxx.xx.com/xxx/xx-xx-cryptohl.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin http://git.xxx.com/xxx/xxx-xxx-cryptohl.git
git push -u origin --all
git push -u origin --tags
 
posted @ 2019-05-21 21:11  panchanggui  阅读(583)  评论(0编辑  收藏  举报