gitinit#创建本地仓库#设置远程仓库地址,这里可以设置ssh或https的形式,此处设置为https格式,#ssh格式为:gitremoteaddorigingit@coding.net:sql031625/test.gitgitremoteaddoriginhttps://git.coding.net/sql031625/test.gittoucha.py#创建文件,使仓库有新的变更gitadd.#添加所有变更gitcommit-m'first'#注释gitpush-uoringinmaster#推送代码,第一次使用-u,以后便可以不使用-u参数#可以设置gitconfig--globalpush.defaultmatching命令,使得push命令默认push到github的同名仓库中

若最后一步出错,

ralap@Ubuntu:~/data/coder/webtest$gitpush-uoriginmasterUsernamefor'https://git.coding.net':sql031625Passwordfor'https://sql031625@git.coding.net':Tohttps://git.coding.net/sql031625/test.git![rejected]master->master(fetchfirst)error:failedtopushsomerefsto'https://git.coding.net/sql031625/test.git'hint:Updateswererejectedbecausetheremotecontainsworkthatyoudohint:nothavelocally.Thisisusuallycausedbyanotherrepositorypushinghint:tothesameref.Youmaywanttofirstintegratetheremotechangeshint:(e.g.,'gitpull...')beforepushingagain.hint:Seethe'Noteaboutfast-forwards'in'gitpush--help'fordetails.

原因分析:在github上重新创建仓库,建立README.md,导致该文件不在本地代码中,执行以下命令,将git仓库中的文件与本地合并,然后再上传即可

gitpull--rebaseoriginmastergitpush-uoringinmaster