After the new github specific steps Repositories

Add User Information

The first is to configure your personal user name and e-mail address. These two configuration is very important, will quote two pieces of information each time you submit Git, indicating who submitted the update, it will be permanently included with the update history together:

      
      
1
2
      
      
config --global git the User .name "username"
config --global git the User .email "Your Email"

SSH key generated and added to github

Check whether they have been ssh keys: cd ~/.ssh. If no key not have this folder, delete the backup there.

ssh-keygen -t rsa -C “你的注册邮箱”

Press 3 Enter the password is blank. Finally we got the two files: id_rsa and id_rsa.pub, to add id_rsa.pub all of SSH Keys in github.

New working directory, and initialize a new local warehouse

      
      
1
2
3
4
      
      
git init
echo "# This is my README" >> README.md // establish README.md file and content This is the # IS My the README
git add . // add all the files to the index (do not want to join all the files, you can use gitignore or add specific file)
the commit git - m . ". First the Commit Adding the README A" // submitted to the local repository, and then will fill in the update log (- m "update log" can also be)

Adding a remote repository and push data to a remote warehouse

  • To add a new remote repository, you can specify a simple name, for future reference, run git remote add [shortname] [url]

Here's what the name is origin added warehouse, this is usually the default.

      
      
1
      
      
remote add origin git @github.com:zhongyouhuiwu/ceshi.git
  • Local data warehouse pushed to the remote repository. Order to achieve this task is simple: git push [remote-name] [branch-name].

If the master branch should be pushed to the origin server (Again, the clone operation will automatically default master name and origin), run the following command:

Large columns github concrete steps after the new Repositories

After the above-described operation is repeated (excluding the operation of the init and romote)

Other commonly used commands

  • Update Project (added a new file):
<  /table>
      
      
1
      
      
git push -u origin master
      
      
1
2
3
4
      
      
cd ~/hello-world
git add .
git commit //提交到本地仓库
git push origin master //不是新创建的,不用再add 到remote上了
  • 更新项目(没新加文件,只有删除或者修改文件):
      
      
1
2
3
      
      
cd ~/hello-world
git commit - a //记录删除或修改了哪些文件
git push origin master //提交到github
  • 忽略一些文件,比如*.o等:
      
      
1
2
3
      
      
cd ~/hello-world
vim .gitignore //把文件类型加入到.gitignore中,保存
然后就可以git add . 能自动过滤这种文件
  • clone代码到本地:
      
      
1
2
3
4
      
      
git clone git @github.com:zhongyouhuiwu/ceshi.git
假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目:
git fetch origin //获取远程更新
git merge origin/master //把更新的内容合并到本地分支
  • 撤销

git reset

  • 删除

git rm * // 不是用rm

常见错误

1.$ git remote add origin [email protected]:zhongyouhuiwu/ceshi.git

错误提示:fatal: remote origin already exists.

解决办法:$ git remote rm origin

然后在执行:$ git remote add origin [email protected]:zhongyouhuiwu/ceshi.git 就不会报错误了

  1. $ git push origin master

错误提示:error:failed to push som refs to

解决办法:$ git pull origin master //先把远程服务器github上面的文件拉先来,再push 上去。

Guess you like

Origin www.cnblogs.com/lijianming180/p/12037789.html