您的位置:首页 > 编程语言

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

2017-05-03 08:10 537 查看
Git环境配置

第一步

第二步

第三步

第四步

clone至本地以及push到Github
clone

push

代码冲突常见解决方法

英文版pull和push教程
Step 1

Step 2 Unnecessary

Step 3

Step 4

Step 5

Step 6

Step 7

Step 8

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[/code] 
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[/code] 
For EXAMPLE:

git clone https://github.com/sharadchhetri/testrepo.git[/code] 
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[/code] 
For EXAMPLE.

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

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.

4000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  github git ssh rsa