Git入门

Git入门

以备份本地小说为例,记录git初步使用方法

陆续更新

本地仓库(repository,又称版本库)
  1. 在某路径下新建一个novel_uptodate版本库,文件夹内右键选择Git Bash Here,打开git命令行。

  2. 用git init命令把该目录编程git可以管理的仓库,之后加入文件。

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate
    $ git init
    Initialized empty Git repository in E:/【ATI】my importance/file/my_world/原创/novel_uptodate/.git/
  3. 使用git add命令将目录中的文件添加到暂存区中。

    • git add *.txt #添加单一文件
    • git add . #添加全部文件
    • git add –all #添加全部文件
    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master)
    $ git add .           #无提示即为成功
  4. 使用git commit命令把文件提交到仓库中,commit命令可以同时提交多个文件。

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master)
    $ git commit -m "update all"
    [master (root-commit) 6313f4c] update all
     19 files changed, 1 insertion(+)
     create mode 100644 README.md
     ......
  5. 可用git status查看当前版本库变化状态。


远程仓库(github)

* 默认已在github上创建账号,并根据提示进行过SSH Key的设置 *

  1. 在github上创建新的仓库,远程仓库名和本地仓库名字相同。

  2. 使用git remote add origin * 仓库地址 * 命令连接本地和远程仓库。

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master)
    $ git remote add origin https://gitee.com/shizusilen/novel_uptodate.git
  3. 使用git push -u origin master命令把本地仓库分支master内容推送到远程仓库,并输入用户名和密码
    如果push出错,有两种方法处理:

    • 先使用git push –rebase origin master进行远程和本地代码合并,再重新执行push
    • 使用git push -u origin master -f强制push
    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master|REBASE 1/1)
    $ git push -u origin master -f
    Username for 'https://gitee.com': ********
    Counting objects: 22, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (20/20), done.
    Writing objects: 100% (22/22), 1.07 MiB | 113.00 KiB/s, done.
    Total 22 (delta 1), reused 0 (delta 0)
    To https://gitee.com/********/novel_uptodate.git
     + b09adc6...6313f4c master -> master (forced update)
    Branch master set up to track remote branch master from origin.
  4. 成功之后,只要本地做了提交,使用git push origin master命令即可


远程仓库(github & 码云)

* 将本地仓库同时关联GitHub和码云 *

  1. 使用多个远程库时要注意,git给远程库起的默认名称是origin,如果有多个远程库,需要用不同的名称来标识不同的远程库。
    因此,先要使用git remote rm origin命令删除已关联的名为origin的远程库

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master|REBASE 1/1)
    $ git remote rm origin
  2. 使用git remote add github * 远程仓库地址 * 命令关联github的远程库

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master|REBASE 1/1)
    $ git remote add github https://github.com/*******/novel_uptodate.git
  3. 使用git remote add gitee * 远程仓库地址 * 命令关联码云的远程库

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master|REBASE 1/1)
    $ git remote add gitee https://gitee.com/*******/novel_uptodate.git
  4. 使用git remote -v命令查看远程库信息

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master|REBASE 1/1)
    $ git remote -v
    gitee   https://gitee.com/********/novel_uptodate.git (fetch)
    gitee   https://gitee.com/********/novel_uptodate.git (push)
    github  https://github.com/********/novel_uptodate.git (fetch)
    github  https://github.com/********/novel_uptodate.git (push)
  5. 使用git push github master命令推送到github(出错解决方法见上)

    madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master|REBASE 1/1)
    $ git push github master -f
    Username for 'https://github.com': *********
    Counting objects: 22, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (20/20), done.
    Writing objects: 100% (22/22), 1.07 MiB | 7.00 KiB/s, done.
    Total 22 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), done.
    To https://github.com/***********/novel_uptodate.git
     + db8c8c9...6313f4c master -> master (forced update)
  6. 使用git push gitee master命令推送到码云(出错解决方法见上)

madhattt@madhattt-PC MINGW64 /e/【ATI】my importance/file/my_world/原创/novel_uptodate (master|REBASE 1/1)
$ git push gitee master
Username for 'https://gitee.com': **********
Everything up-to-date
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值