关于github不清楚的可以百度,

在这里,可以创建一个新的仓库

点击Create repository后会出现下面这些信息,其中第一块是仓库的url链接

第二块是你在本地目录中创建一个READEME.md文件,然后进行初始化,在add和commit提交到分支,然后再关联仓库,最后通过push 推送本地代码到github。

第三块其实就是已创建了本地仓库的前提下,执行第二块后面两行命令,推送代码到github

$ git remote add origin git@github.com:LaoNiNi/Test.git
fatal: remote origin already exists. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git push -u origin master
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
To github.com:LaoNiNi/Test.git
87faef8..43b2fe4 master -> master
Branch master set up to track remote branch master from origin. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$

现在我们可以通过url来把代码clone到本地

通过 git branch -r 可以查看本地和远程相关联的git分支有哪些。通过push时指定提交分支,可以让分支和远程分支关联。

laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git branch -r
origin/master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git branch
* master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git branch dev laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git branch
dev
* master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ gir branch -r
bash: gir: command not found laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git branch -r
origin/master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git branch dev
fatal: A branch named 'dev' already exists. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git push -u origin dev
Total (delta ), reused (delta )
To github.com:LaoNiNi/Test.git
* [new branch] dev -> dev
Branch dev set up to track remote branch dev from origin. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git branch -r
origin/dev
origin/master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$

git branch

当别的同事create和push新的分支到github时,我可以通过git branch -a 查看本地分支和远程分支有哪些,我们clone代码时只会把默认分支(master)clone到本地,并不包括别的分支,所以需要通过 git checkout -b bug /origin/bug 命令创建新分支,并且切换到新分支,而且关联远程的bug分支。

通过git remote -v 可以查看当前关联哪个远程git,通过git remote remove origin可以删除当前关联项

laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git remote -v
origin git@github.com:LaoNiNi/Test.git (fetch)
origin git@github.com:LaoNiNi/Test.git (push) laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git remote remove origin laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (master)
$ git remote -v

使用git pull origin 分支名称 可以更新远程分支,并且合并我当前分支,如果有冲突,会在本地有冲突的文件里出现提示。

$ git add *

laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git status
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: README.md
new file: README2.md laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git commit -m "commit newfile"
[master (root-commit) ae86fce] commit newfile
files changed, insertions(+)
create mode README.md
create mode README2.md laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git push origin dev
error: src refspec dev does not match any.
error: failed to push some refs to 'git@github.com:LaoNiNi/Test.git' laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git push origin master
To github.com:LaoNiNi/Test.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:LaoNiNi/Test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git pull origin master
warning: no common commits
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused
Unpacking objects: % (/), done.
From github.com:LaoNiNi/Test
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git push origin master
To github.com:LaoNiNi/Test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:LaoNiNi/Test.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. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ lws
bash: lws: command not found laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git status
On branch master
nothing to commit, working tree clean laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$

git pull push

但是git pull会自动帮我们合并分支,帮我们隐藏了很多细节,这样不能很好的掌控代码变化细节,

$ git add README2.md

laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) modified: README2.md laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git commit -m "提交 This is a new file"
[master 6efcf83] 提交 This is a new file
file changed, insertions(+) laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git status
On branch master
nothing to commit, working tree clean laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git push origin master
To github.com:LaoNiNi/Test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:LaoNiNi/Test.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. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git pull origin master
From github.com:LaoNiNi/Test
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ cat README2.md
# Test This is a new file. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git push origin master
To github.com:LaoNiNi/Test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:LaoNiNi/Test.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. laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git branch -a
* master
remotes/origin/master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ git checkout origin/master
Note: checking out 'origin/master'. You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at 43b2fe4... second commit laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 ((43b2fe4...))
$ cat README2.md
# Test laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 ((43b2fe4...))
$ git branch -a
* (HEAD detached at origin/master)
master
remotes/origin/master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 ((43b2fe4...))
$ git checkout master
Previous HEAD position was 43b2fe4... second commit
Switched to branch 'master' laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test2 (master)
$ cat README2.md
# Test This is a new file. laoni@DESKTOP-TPPLHIB MINGW64 /c/laon

所以我们合并分支时,可以用merge  加上  --no-ff参数这样有问题可以撤销:

laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test ((fc4efc3...))
$ cat README.md
哇哈哈 def adb():
aa =
bb = laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test ((fc4efc3...))
$ git pull origin master
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
Unpacking objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused
From github.com:LaoNiNi/Test
* branch master -> FETCH_HEAD
fc4efc3..83aa53b master -> origin/master
Updating fc4efc3..83aa53b
Fast-forward
README.md | +-
file changed, insertion(+), deletion(-) laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test ((83aa53b...))
$ cat README.md
哇哈哈6666666666666666666666666666666666 def adb():
aa =
bb = laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test ((83aa53b...))
$ git checkout origin/master
HEAD is now at 83aa53b... third remove laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test ((83aa53b...))
$ git branch -a
* (HEAD detached from d405ab6)
dev
master
remotes/origin/master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test ((83aa53b...))
$ cat README.md
哇哈哈6666666666666666666666666666666666 def adb():
aa =
bb = laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test ((83aa53b...))
$ git checkout dev
Previous HEAD position was 83aa53b... third remove
Switched to branch 'dev' laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (dev)
$ git branch -a
* dev
master
remotes/origin/master laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (dev)
$ git merge origin/master --no-ff
Merge made by the 'recursive' strategy.
README.md | +++++-
README2.md | ++++
files changed, insertions(+), deletion(-) laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (dev)
$ cat README.md
哇哈哈6666666666666666666666666666666666 def adb():
aa =
bb = laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (dev)
$ git log --oneline
bbb0d30 Merge remote-tracking branch 'origin/master' into dev
83aa53b third remove
fc4efc3 哇哈哈
d405ab6 second remove
README.md remove
98aa011 abc
6efcf83 提交 This is a new file
ae86fce commit newfile
43b2fe4 second commit
87faef8 first commit laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/new_test (dev)
$

git 和github简介的更多相关文章

  1. Git 与 GitHub 简介

    Git 与 GitHub 的来历 Linux 之父 Linus 在 1991 年创建开源的 Linux 操作系统之后,多年来依靠全世界广大热心志愿者的共同建设,经过长足发展,现已成为世界上最大的服务器 ...

  2. Git和Github的介绍、简单操作、冲突(上)

    目的:   1.git与github简介  2.Git与SVN区别 3.Github 的简单使用 4.下载安装Git-20-64-bit.exe   5.Git常用命令 5.1Git命令使用场景 5. ...

  3. git和github入门指南(1)

    1.git和github简介 1.1.git是什么?github是什么?git和github的关系? Git是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理. Git ...

  4. git与github区别与简介

    From: https://blog.csdn.net/skyxmstar/article/details/65631658 git和github是两个完全不同的概念. git 是一个版本管理工具,是 ...

  5. Git(1) - Git、Github和Gitlab简介

    Git是什么 概念 Git(读音为/gɪt/.)是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理. SVN.CVS等,它们是集中式版本控制系统. 集中式和分布式版本控制 ...

  6. 【风马一族_git_github】git与github的英文记录

    Pull requests  Issues Gist 请求 问题 要点 ---------------------------------------------------------------- ...

  7. 知识扩展——Git和GitHub的区别

    一直以为Git和GitHub是一个东西,直到我看到这个解释.... 转载自:git与github区别与简介 一开始接触git或是github的程序员可能搞不太清楚这些名词到底指代的是什么,所以在这里稍 ...

  8. [git与github]__git与github简单了解

    前言 关于版本控制,版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统. 我们通过版本控制系统可以解决的问题:可以非常方便的查看我们的源码文件的历代更新版本.或将我们的项目源 ...

  9. 本地Git与GitHub服务器建立连接(SSH方式通信)

    简介 Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要 ...

随机推荐

  1. MySQL总结02

    sql优化 Insert使用批量 查询不要使用*, MySQ需要先查出表里的所有字段,再进行匹配 字符串的查询条件要带引号,否则可能不走索引 备份及恢复 备份 mysqldump -uroot -pp ...

  2. Machine code transfer into assembly code

    #include <stdio.h> const char shell[]="\x0f\x01\xf8\xe8\5\0\0\0\x0f\x01\xf8\x48\xcf" ...

  3. Error (10170): Verilog HDL syntax error at passwd.v(21) near text "if"; expecting an identifier ("if" is a reserved keyword ), or "endmodule", or a parallel statement

    你得加上时序啊笨蛋

  4. 面试题: nodejs 的事件轮询机制

    setTimeout(function(){ console.log('setTimeout()执行了') },0) setImmediate(function(){ console.log('set ...

  5. MHA-Atlas-MySQL高可用(下)

    MHA-Atlas-MySQL高可用(下) 链接:https://pan.baidu.com/s/17Av92KQnJ81Gc0EmxSO7gA 提取码:a8mq 复制这段内容后打开百度网盘手机App ...

  6. Translucent System Bar 的最佳实践

    转自:http://www.jianshu.com/p/0acc12c29c1b 近几天准备抽空总结Android一些系统UI的实践使用,于是开始动手建了一个库 AndroidSystemUiTrai ...

  7. 1、Python 基础类型 -- Number 数字类型

    一.Number

  8. mysql查询相关

    查询事务 SELECT * FROM information_schema.INNODB_TRX\G; 查询正在锁的事务 SELECT * FROM INFORMATION_SCHEMA.INNODB ...

  9. react-native run-android出现红屏错误

    react-native run-android出现 unable to load script from assets 'index.android.bundle'.Make sure your b ...

  10. Hadoop常用端口和定义方法

    Hadoop集群的各部分一般都会使用到多个端口,有些是daemon之间进行交互之用,有些是用于RPC访问以及HTTP访问.而随着Hadoop周边组件的增多,完全记不住哪个端口对应哪个应用,特收集记录如 ...