【Github】Github命令行快速使用教程及常见问题解决
来源:互联网 发布:网络主播李叫兽 下载 编辑:程序博客网 时间:2024/05/21 22:26
- 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
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.
- 【Github】Github命令行快速使用教程及常见问题解决
- Github使用常见问题及Git命令教程
- GitHub使用教程及常见错误解决
- GitHub使用教程及常见错误解决
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- GitHub版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- github版本库使用详细教程(命令行及图形界面版)
- 利用 Chrome 开发者工具远程调试 Android 中的原生 WebView
- VS设置高亮显示
- pcap文件格式
- OGNL表达式的粗浅理解
- BZOJ 2190 [SDOI2008]仪仗队——欧拉函数
- 【Github】Github命令行快速使用教程及常见问题解决
- 自动化测试中各种流量的模拟1
- iOS监听手机锁屏状态
- RecyclerView的适配器的使用
- 【reids】redis持久化 RDB和AOF
- 矩阵——P2886 [USACO07NOV]牛继电器Cow Relays
- C++primer学习笔记-----5.4~5.5
- 基于ARM9:Thumb指令系统和ARM指令系统
- JQuery this和$(this)的区别及获取$(this)子元素对象的方法