github本地库创建分支和合并分支以及提交到github远程库中的方法

开源技术 GitHub 专栏收录该内容
7 篇文章 0 订阅

前提:在github上手动创建仓库如:javaConsole

然后拷贝地址:https://github.com/hsg77/javaConsole.git

在本地按照如下的命令进行
#新建工程
mkdir javaConsole 
#或者IJ ide创建新工程目录,然后进入到新工程的根目录,然后cmd中初始化本地仓库git init

#如果是已存在的工程项目,则直接cd到项目根目录下,不需要新建。
cd javaConsole
#初始化本地仓库
git init 

#添加要push到远程仓库的所有文件或文件夹
git add *

#添加要push到远程仓库的指定的文件xxx或文件夹xxx
git add xxx     

#提交修改代码到本地master仓库
git commit -m ‘first commit’

#建立远程仓库
git remote add origin https://github.com/hsg77/javaConsole.git 

#可以通过如下命令进行本地代码与远程仓库代码的合并【注:pull=fetch+merge]
#下载并合并
git pull --rebase origin master

#将本地仓库代码push到远程仓库
git push -u origin master 
需要注意的是:一定要在github上手动创建仓库javaConsole

Administrator@hsgpc MINGW32 /
$ pwd
/

Administrator@hsgpc MINGW32 /
$ cd hsg77

Administrator@hsgpc MINGW32 /hsg77 (master)
$ ls
HelloWorld/  HelloWorld_C#/

Administrator@hsgpc MINGW32 /hsg77 (master)
$ git clone git@github.com:hsg77/gitskills.git
Cloning into 'gitskills'...
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

Administrator@hsgpc MINGW32 /hsg77 (master)
$ ls
gitskills/  HelloWorld/  HelloWorld_C#/

Administrator@hsgpc MINGW32 /hsg77 (master)
$ cd gitskills

Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ ls
README.md

Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ pwd
/hsg77/gitskills

Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ cd ..

Administrator@hsgpc MINGW32 /hsg77 (master)
$ pwd
/hsg77

Administrator@hsgpc MINGW32 /hsg77 (master)
$ ^C

Administrator@hsgpc MINGW32 /hsg77 (master)
$ pwd
/hsg77

Administrator@hsgpc MINGW32 /hsg77 (master)
$ cd gitskills
pwd

Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ pwd
/hsg77/gitskills

Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git checkout -b dev
Switched to a new branch 'dev'

Administrator@hsgpc MINGW32 /hsg77/gitskills (dev)
$ git branch
* dev
  master

Administrator@hsgpc MINGW32 /hsg77/gitskills (dev)
$ current branch is dev
bash: current: command not found

Administrator@hsgpc MINGW32 /hsg77/gitskills (dev)
$ git status
On branch dev
Untracked files:
  (use "git add <file>..." to include in what will be committed)


        readme.txt


nothing added to commit but untracked files present (use "git add" to track)


Administrator@hsgpc MINGW32 /hsg77/gitskills (dev)
$ git add readme.txt


Administrator@hsgpc MINGW32 /hsg77/gitskills (dev)
$ git commit -m "branch test"
[dev eae0249] branch test
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt


Administrator@hsgpc MINGW32 /hsg77/gitskills (dev)
$ go to master branch
bash: go: command not found


Administrator@hsgpc MINGW32 /hsg77/gitskills (dev)
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ pwd
/hsg77/gitskills
ls


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ ls
README.md


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git branch
  dev
* master


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ current branch is master *
bash: current: command not found


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git merge dev
Updating 036583a..eae0249
Fast-forward
 readme.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ ls
README.md  readme.txt


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ delete branch dev
bash: delete: command not found


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git branch -d dev
Deleted branch dev (was eae0249).


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git branch
* master


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ pwd
/hsg77/gitskills
ls


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ ls
README.md  readme.txt


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$
git
Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git push origin master
Warning: Permanently added the RSA host key for IP address '192.30.252.120' to the list of known hosts.
ERROR: Permission to hsg77/gitskills.git denied to deploy key
fatal: Could not read from remote repository.


Please make sure you have the correct access rights
and the repository exists.


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git remote add origin_stills git@github.com:hsg77/gitskills.git


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git push origin_stills master
ERROR: Permission to hsg77/gitskills.git denied to deploy key
fatal: Could not read from remote repository.


Please make sure you have the correct access rights
and the repository exists.


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ pwd
/hsg77/gitskills


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ ssh-keygen -t rsa -C "hsg77@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:n7kbnT/FQ22GSO+Zt8HKiBp7796N9X/wExdsxylZjz0 hsg77@163.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|            .  . |
|           . o+=+|
|            .o+EO|
|        S    .=*+|
|         . + .===|
|       .  * = .**|
|        oo +.+=o+|
|       oo *= o.o*|
+----[SHA256]-----+


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ git push origin_stills master
Warning: Permanently added the RSA host key for IP address '192.30.252.123' to the list of known hosts.
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 299 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:hsg77/gitskills.git
   036583a..eae0249  master -> master


Administrator@hsgpc MINGW32 /hsg77/gitskills (master)
$ OK

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值