编程工具-git的使用:创建远程仓库,提交代码

git简介:

git用于代码管理。在git中,代码首先要存储在远程仓库,本文简单说明如何建立远程仓库,以及push本地代码到远程仓库的过程。主要分为三步:建立本地仓库并comit代码;建立远程仓库;进行仓库关联并提交代码(从本地仓库提交到远程仓库)。这里的远程就是服务器,本地就是你当前的电脑。

git创建远程仓库并进行代码提交使用举例:

(1)建立本地仓库并comit代码:

建立本地仓库:git init

进入到存放代码的目录下,用git init建立本地仓库:

% git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /Users/user/work/src/testsrc/.git/

结果,会在当前文件夹下创建.git目录,内容如下:

% cd .git

.git % ls

HEAD config description hooks info objects refs

 

提交代码(commit):

% git add .      //1.添加代码
% git status     //2.查看状态(可以省略者一步)
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   test.c

% git commit -m "new"       //3. 提交代码到本地仓库
[master (root-commit) b9b2f83] new
 1 files changed, 7 insertions(+)

% git branch        //查看分支
* master

这样,本地代码仓库就建好了,而且,代码也提交到本地仓库了。

(2)建立远程仓库:

在github网站上创建远程仓库:

选择 Repositories,【new】一个仓库,在Create  a new repositorie界面,输入repositorie name,创建即可。

(3)将本地仓库和远程仓库进行关联并push代码:

仓库关联,命令如下:

git remote add 别名 远程仓库地址 ,如下:

git remote add auto-policy-python git@192.168.128.211:usercon/test-src-c.git

 push代码到远程仓库:

git push -u test-src-c master   

% git push -u auto-policy-python master                                                  
Enter passphrase for key '/Users/user/.ssh/id_rsa': 
Enumerating objects: 39, done.

总结:

用到的命令如下:


git init     //建立本地仓库

git add . //将当前文件夹下的所有文件添加到暂存区

git commit -m "message"  //提交到本地仓库

在github网站上创建远程仓库

git remote add  alias remote_addr //将本地仓库和远程仓库进行关联

git push -u   //将文件push到远程仓库


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liranke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值