【Github】Github命令行快速使用教程及常见问题解决

Git环境配置

第一步:

生成ssh key,使用命令 “ssh-keygen -t rsa -C “your_email@youremail.com””,your_email是你的email默认在用户的家目录下.ssh/id_rsa.pub文件里面

第二步:

回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。

第三步:

测试ssh key是否成功,使用命令“ssh -T git@github.com”,如果出现You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。

如果出现“Agent admitted failure to sign using the key.Permission denied (publickey).”这个错误的话,在命令行下执行”ssh-add”,这样就可以了。

第四步:

配置Git的配置文件,username和email

git config --global user.name "your name"   //配置用户名
git config --global user.email "your email"    //配置email 

clone至本地以及push到Github

clone

git clone https://github.com/chenguolin/scrapy.git
git pull origin master

push

git add xxx
git commit -m
git push origin master

代码冲突常见解决方法

如果系统中有一些配置文件在服务器上做了配置修改,然后后续开发又新添加一些配置项的时候,

在发布这个配置文件的时候,会发生代码冲突:

error: Your local changes to the following files would be overwritten by merge:
protected/config/main.php
Please, commit your changes or stash them before you can merge.

如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:

git stash
git pull
git stash pop
然后可以使用Git diff -w +文件名 来确认代码自动合并的情况.

反过来,如果希望用代码库中的文件完全覆盖本地工作版本. 方法如下:

git reset –hard
git pull
其中git reset是针对版本,如果想针对文件回退本地修改,使用

git checkout HEAD file/to/restore  

英文版pull和push教程

In below section, I am writing step by step how I pushed the code in Github repo successfully
Follow the given below steps from where(Desktop/Server) you want to push the code into Github repo :

Step 1:

Clone the github repo into your system. (You should first create a repo in Github)

Get repo url at right hand sidebar of your repo page. Replace your github repo’s HTTPS url with https://github.com/USER-NAME/REPO-NAME.git

git clone https://github.com/USER-NAME/REPO-NAME.git

For EXAMPLE:

git clone https://github.com/sharadchhetri/testrepo.git

After cloning will be finished, you will find the directory name matching with the name of Github repo name you just cloned.

Step 2 : (Unnecessary)

Copy your code or files to REPO-NAME directory

For example, I have saved my codes in my desktop at /home/sharad/MyCode directory. Here, I am copying all codes and child directories into REPO-NAME directory .

cp -rvf /home/sharad/MyCode/* /home/sharad/testrepo

Step 3 :

Change to git cloned directory i.e REPO-NAME.

cd REPO-NAME

Step 4 :

Set Github account username and email id for authentication

git config --global user.email "your-email-id@example.com"
git config --global user.name "Your-Github-UserName"

Step 5:

Set Github URL. (This section is actually solution of this problem)

git remote set-url origin https://Your-Github-UserNAme@github.com/Your-Github-UserNAme/REPO-NAME

For EXAMPLE.

git remote set-url origin https://sharadchhetri@github.com/sharadchhetri/testrepo.git

Step 6:

Now add all files and directory by using below given command inside REPO-NAME directory
(There is a dot in command, can you see that!)

git add .

Step 7:

Now write comment on commit

git commit -m 'my first commit'

Step 8:

Now push the code in Github repo.
Be ready with your github account password because it will ask.

git push -u origin master

I hope the solution also work for you.

全部评论

相关推荐

不愿透露姓名的神秘牛友
05-29 22:21
Offer1:小马智行,深圳,测试开发工程师,17.0k*16.0,Offer2:追觅科技,深圳,嵌入式工程师,18.0k*15.0,
嵌软狗都不学:各位base深圳的同事,作为也是并肩作战的一员,今天想站在管理视角,和大家开诚布公地聊一聊:从近几个月的上下班数据对比看来,我们发现一个明显的差异:深圳同事的在岗时间普遍比苏州同事短。很多深圳同事早上9点之后才到公司,晚上不到 20 点就下班了;而总部那边,20点半甚至 22 点后还有不少同事在办公室忙碌,特别是研发团队,加班更是常态。相信去过苏州的同事,对这种场景都不陌生。我很好奇,这是因为苏州工作任务太重还是咱们深圳同事效率真的高到能在更短时间内完成工作?MOVA在深圳成立分公司是为了吸引更优秀的人才贡献更多更高质的价值,公司管理层给我反馈的是深圳招到的多是行业的专家大拿,大部分都是薪资比苏州高的,而且我们办公的租金等也远高于苏州的..MOVA虽脱胎于强壮的集团母体不久,各业务板块尚未实现全面盈利,虽说公司管理层目光长远,不纠结当下的人才投入,但行业内的普遍标准是,员工创造的价值要达到公司雇佣成本的 15 倍以上。大家不妨自我审视一下,自己是否达到了这个标准?如果是抱着划水、按时打卡走人拿毛爷爷的心态那不适合来MOVA,那样过下去不但自己过得尴尬也会影响MOVA这个大船的攻城略地的速度.我并非鼓励大家盲目加班,而是倡导高效工作,拒绝无效忙碌,不要让项目进度因低效受影响,也别把精力浪费在和苏州同事拼打卡时长上,提倡更高的人效比;考虑到两地地域和交通差异,相信大家会找最适合自己发挥的工作方式(比如按时下班后1小时到家晚饭后继续未竟工作等..)大家在遵守公司规章的情况下尽情地体现自己的能力价值,为MOV!和深圳公司争光我们在这边才能更安心更有信心的工作下去;请客BU长、名部门长、项目管理和各业务单元负责人,全面梳理团队情况,及时评估成员工作负荷与成果质量,坚决清退划水害虫痕疫,践行公司价值观,相互监督,防止管理漏洞及渎职。感谢人家的理解,也请人家多担待我的直言不讳……
点赞 评论 收藏
分享
CADILLAC_:我要用bava 不要用java 了 啊啊啊啊啊啊啊啊啊啊啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务