注册github账号

github地址,进入注册账号

安装git

Windows下载地址1

Windows下载地址2

在官方下载完后,双击exe文件进行安装,安装到Windows Explorer integration的时候,将选项中的“Git Bash here”和“Git GUI here”打对勾。

获取SSH key

1、 右键鼠标,选中 “Git Bash here”,或者安装目录打开它

2、 进入Git Bash Here后输入以下命令:

cd ~/.ssh/

如果出现提示:No such file or directory(没有这样的文件或目录)

执行以下命令创建即可:

mkdir ~/.ssh

3、 执行以下两个命令配置全局的name和email,这里是的你github登陆名和邮件地址

git config --global user.name "xxx"

git config --global user.email "xxx@163.com"

就是注册时输入的这两个内容,如下图:

4、 生成key

ssh-keygen -t rsa -C "xxx@163.com"

连续按三次回车,设置了密码为空,并且创建了key,最后得到了两个文件:id_rsa和id_rsa.pub(记住生成过程中提示的生成key文件路径,后面要用到)

在github配置SSH key

1、 登陆github → 进入设置(Settings)

2、 新建SSH key

3、 将本地生成的key放入github,步骤如下:

3.1 进入我们前面生成SSH key的路径C:\Users\xxx\.ssh(根据自己生成时的路径去找)

3.2 用记事本打开id_rsa.pub,将内容全部复制

放入github

添加后

测试是否成功

进入Git Bash Here后输入以下命令:

ssh git@github.com

出现类似提示就代表成功了:Hi xxx! You’ve successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed

在Pycharm添加github账户

进入pycharm,settings → Version Control → 添加github账户

开始上传

1、进入Pycharm选择VCS → Import into Version Control → Share Project on GitHub

接着会让你选择项目文件,如果不太熟悉建议把项目都选免得遗漏,出现以下提示就证明成功了。

进入github主页/我的仓库就可以看到我们新同步的代码了

Pycharm拉取或更新代码

DOS中使用的常用命令

1、获取github上的项目代码命令如下:

git clone https://github.com/weibgg/django.git

2、配置git默认配置为忽略大小写:

git config core.ignorecase false

3、更新github代码

第一步:查看当前的git仓库状态,可以使用git status

D:\xuexi\python\django (master)
>>> git status
On branch master
Your branch is up to date with 'origin/master'. Untracked files:
(use "git add <file>..." to include in what will be committed) ../.idea/
../__init__.py
my_site/my_site/__pycache__/
test_push.txt nothing added to commit but untracked files present (use "git add" to track)

第二步:更新全部git add *git add .当前目录

D:\xuexi\python\django (master)
>>> git add *

第三步:接着输入git commit -m "更新说明"

D:\xuexi\python\Python基础\django (master)
>>> git commit -m "20180001bug修复"
[master d1ee53c] 20180001bug修复
5 files changed, 1 insertion(+)
create mode 100644 django/my_site/my_site/__pycache__/__init__.cpython-36.pyc
create mode 100644 django/my_site/my_site/__pycache__/settings.cpython-36.pyc
create mode 100644 django/my_site/my_site/__pycache__/urls.cpython-36.pyc
create mode 100644 django/my_site/my_site/__pycache__/wsgi.cpython-36.pyc
create mode 100644 django/test_push.txt

第四步:git fetch --all拉取当前分支最新代码(如果是多人同时开发,类似SVN提交前先update)

D:\xuexi\python\django (master)
>>> git fetch --all
Fetching origin

注意: git fetch --all(只是下载代码到本地,不进行合并操作)git pull(下载并覆盖本地代码)

第五步:push到远程master分支上git push origin master

D:\xuexi\python\django (master)
>>> git push origin master
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (11/11), 2.89 KiB | 422.00 KiB/s, done.
Total 11 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/weibgg/django_blog.git
369f642..d1ee53c master -> master

执行到这里不出意外在github就能看到更新后的代码了

常见错误

因为项目的变更需要同步的github项目地址变动,如下面示例项目地址已修改找不到路径,需要同步变更地址最简单的办法删除项目中的.get文件夹重新配置远程仓库,也可以查看此教程 git 修改远程仓库地址详解

D:\xuexi\python (master)
>>> git push origin master
remote: Repository not found.
fatal: repository 'https://github.com/weibgg/test.git/' not found

出现如下报错:

>>> git push origin master
To https://github.com/weibgg/django.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/weibgg/django.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决参考

出现如下提示:

>>> git add *
warning: LF will be replaced by CRLF in .idea/dataSources/6c0c039e-d9ac-4487-9fc3-ffda4f80776b.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory

原因:在非项目文件执行了更新操作

跳转至顶部

Pycharm同步本地代码至GitHub的更多相关文章

  1. Git安装配置和提交本地代码至Github,修改GitHub上显示的项目语言

    1. 下载安装git Windows版Git下载地址: https://gitforwindows.org/ 安装没有特别要求可以一路Next即可,安装完成后可以看到: 2. 创建本地代码仓库 打开G ...

  2. git 本地代码到github

    一·什么是gitHub? 官网解释:gitHub是一个让无论处于何地的代码工作者能工作于同一个项目,同一个版本的平台.(GitHub is a code hosting platform for ve ...

  3. git配置SSH Key,上传本地代码至github

    git配置全局的name和email git config --global user.name "name" git config --global user.email &qu ...

  4. git 本地代码到github(转)

    git 本地代码到github   一·什么是gitHub? 官网解释:gitHub是一个让无论处于何地的代码工作者能工作于同一个项目,同一个版本的平台.(GitHub is a code hosti ...

  5. 使用VS2015将解决方案同步更新到Github上

    如今开源已经是一种趋势与潮流了,今天就来谈一谈如何将利用VS将我们的解决方案同步更新到Github上. 第一步:登录自己的Github账号(没有的自行注册). 我的Github登录后的界面: 第二步: ...

  6. mac 上传本地代码到 Github 教程

    网上有很多关于windows系统上传本地代码到github的文章,但是自己用的是mac,在网上也找了相关文章,实践的过程中还是遇到了很多问题,现在把自己的成功实践分享出来,希望能对大家有帮助. 1.首 ...

  7. Pycharm中Git、Github的简单使用和配置

    Pycharm中Git.Github的使用 PyCharm本身自带了git,稍微配置一下就可以很好的在图形界面下进行Python项目的版本控制 配置Git 在配置前先新建一个项目,当然也可以打开已有的 ...

  8. Git同步更新操作GitHub和码云仓库上面的代码

    一.前言 问题: 小编在生活中,一般都是将代码保存到github上,但由于国内的码云仓库确实速度比github快很多,用起来也很方便,于是后来就慢慢转码云了,当然小编在github上的代码也不想放弃更 ...

  9. Git使用的一些问题:.gitignore规则不生效、git同步代码至github和gitee

    Git忽略规则及.gitignore规则不生效的解决办法 .gitignore 的基本使用 在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件 ...

随机推荐

  1. no plugin found for prefix 'tomcat 7' in the current project

    使用maven build编译出错 “no plugin found for prefix 'tomcat 7' in the current project..........” 参照下面方法 ht ...

  2. AJAX的来龙去脉(由来)-如何被封装出来的--ajax发送异步请求(四步操作)

    <黑马程序员_超全面的JavaWeb视频教程vedio\JavaWeb视频教程_day23_ajax> \JavaWeb视频教程_day23_ajax\day23ajax_avi\14.打 ...

  3. Windows10安装Ubuntu子系统设置Python3测试环境

    参考链接:https://blog.csdn.net/shanelee73/article/details/80238876

  4. OVS-----CentOS7.2上安装OVS软件

    1.安装依赖包: yum -y install make gcc openssl-devel autoconf automake rpm-build redhat-rpm-config yum -y ...

  5. RabbitMQ应用场景

    1.背景 RabbitMQ是一个由erlang开发的AMQP(Advanved Message Queue)的开源实现. 2.应用场景 2.1异步处理 场景说明:用户注册后,需要发注册邮件和注册短信, ...

  6. python三大神器

    Python 中有很多优秀的包,本文主要讲一下 pip, virtualenv, fabric 1. pip 用来包管理 文档:https://pip.pypa.io/en/latest/instal ...

  7. nginx使用https协议

    效果: nginx添加ssl模块 ./configure --with-http_ssl_module 生成证书 openssl genrsa -out ca.key 2048 openssl req ...

  8. 系统更新报错--NO_PUBKEY

    错误信息 W: An error occurred during the signature verification. The repository is not updated and the p ...

  9. 关于Jonathan S. Weissman与RIT(罗切斯特理工学院,位于纽约)

    信息来源于:edx平台的 RITx: CYBER501xCybersecurity Fundamentals  课程的介绍(https://courses.edx.org/courses/course ...

  10. Golang记录、计算函数执行耗时、运行时间的一个简单方法

    // 写超时警告日志 通用方法   func TimeoutWarning(tag, detailed string, start time.Time, timeLimit float64) {    ...