GIt Basic

  1. ssh-keygen 在本地电脑中中生成钥匙
  2. 打开公钥id-rsa.pub ,将公钥copy到git网站的SSH KEYS 中。
  • git clone 将服务器中的代码git到本地,copy项目网页上的ssh连接
  • 提交代码
  1. 先创建一个branch ,进入项目目录,输入命令行git branch username 这个样就创建了一个本地的branch.
    输入git checkout username转到当前branch
    git branch 查看本地多少branch. 查看远程分支
    git branch -r
  2. 在目录中添加新文件后,可以git status 看一下文件改变状态
  3. 之后git add 确定添加 参数-u 代表更新的代码, 参数-A 表示所有,add到本地仓库
  4. 之后git commit -m "作用" 将,参数-m表示本次提交描述,表示确认提交到本地仓库
  5. git push -u orgin youbranch 提交到远程
    注:
  • $ git push -u origin master //第一次提交添加命令参数 -u 确保关联本地库和远程库
  • $ git push origin master //非第一次提交使用此命令即可)

如果出现报错

$ git push -u origin master命令的时候报错:To [email protected]:xxx/xxx.git 
! [rejected] master -> master (fetch first) 
error: failed to push some refs to '[email protected]:xxx/xxx.git' 
hint: Updates were rejected because the remote contains work that you do 
hint: not have locally. This is usually caused by another repository pushing 
hint: to the same ref. You may want to first integrate the remote changes 
hint: (e.g., 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因是没有同步远程的master,所以需要先执行命令git pull origin master同步代码
之后就可以同步了。

  1. git pull -r 将项目代码拉到本地。

你可能感兴趣的:(GIt Basic)