zoukankan      html  css  js  c++  java
  • 用命令在本地创建github仓库

    问题

    每次创建github仓库,都要到github官网,有点麻烦,想在本地直接创建github仓库,写好项目后直接push。
    操作系统:linux

    步骤

    1, 首先在github申请一个私人api token。 申请地址:https://github.com/settings/tokens/new
    申请时taken权限一般全部勾选。系统生成Token码,先复制保存到本地,注意再次打开就看不到了,如果忘了就从新生成。
    而且如果自己项目里面包含该taken,则这个taken也会失效。

    2, 配置.bashrc文件,写一个自动生成仓库的命令。在本机使用的bash的配置文件中加入下述函数定义。

    github-create() 
    {if [ -n "$1" ]
    then
        repo_name=$1
    else
        repo_name=`pwd | xargs basename`
    fi 
    
    echo "set Repo name to ${repo_name}"
    curl -u 'username:api_token' https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
    git remote add origin git@github.com:username/$repo_name.git
    }
    
    **使用自己的username与api_token覆盖上述函数中相应的值。**
    
    注意以下几点:
    - [ $1 ],$1两侧必须有空格
    - 配置了github的ssh登录
    

    3, 重启配置文件 . ./.bashrc。 使用方法:github-create repo_namegithub-create(默认当前目录为仓库名),注意使用命令的当前目录下必须有本地仓库,即有.git文件夹在。


    将本地代码仓库push到github远程代码仓库

     以下省去在本地创建git仓库以及提交commit等操作。

     (1)首先将本地仓库和远程代码仓库进行关联:

     git remote add origin your_repo_url.git

     (2)然后将本地代码仓库push到github:

     git push -u --set-upstream origin master

  • 相关阅读:
    myeclipse 代码提示(alt+/)
    彻底解决mysql中文乱码
    Pycharm取消默认的右击运行unittest方法
    解决Ubuntu的root账号无法登录SSH问题-Permission denied, please try again.
    language support图标在哪里?怎么消失了?
    Ubuntu安装谷歌输入法或者搜狗
    最大流算法-ISAP
    WC2013-糖果公园
    bzoj4032-最短不公共子串
    bzoj1031-字符加密
  • 原文地址:https://www.cnblogs.com/friedCoder/p/12255041.html
Copyright © 2011-2022 走看看