常见指令
git init //把这个目录变成Git可以管理的仓库
git add README.md //文件添加到仓库
git add . //不但可以跟单一文件,还可以跟通配符,更可以跟目录。一个点就把当前目录下所有未追踪的文件全部add了
git commit -m "first commit" //把文件提交到仓库
git remote add origin git@github.com:nidegitdizi/practice.git //关联远程仓库
git push -u origin master //把本地库的所有内容推送到远程库上
查看系统config
git config --system --list
查看当前用户(global)配置
git config --global --list
查看当前仓库配置信息
git config --local --list
查看密钥是否生成
cd ~/.ssh
密钥路径
C:\Users\wangyajun\.ssh
git pull --rebase origin master (pull=fetch+merge)
将b分支合并到当前分支
git merge b
步骤
1.GitHub创建账号 创建远程库

2.本地安装git
设置环境变量 : ,
一般情况下我们默认使用Git Bash即可, 默认选择;
Git自带 : 使用Git自带的Git Bash命令行工具;
3.本地配置



初始化本地git:
git init
git add .
git commit -m "cesi"
git remote add origin git@github.com:shuaiguo9/practice.git
git push -u origin master
4.GitHub配置ssh key
4.0 查看本地是否已经有ssh了
cd ~/.ssh
或本地路径
C:\Users\wangyajun\.ssh
都可以查看是否有公钥

没有,则生成新的密钥
ssh-keygen -t rsa -C "youremail@example.com"
密钥类型可以用 -t 选项指定。如果没有指定则默认生成用于SSH-2的RSA密钥。这里使用的是rsa。
然后连续回车3次,在你的C:\Users\wangyajun\.ssh中就能看到生成的密钥,复制id_rsa.pub文件内容。到下图中
4.1 右上角

4.2 个人中心设置里

4.3 最后配置完成

Error
git push -u origin master 报错
To github.com:sky1339m/Test.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:sky1339m/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.
原因:github中的README.md文件不在本地代码目录中
解决:git pull --rebase origin master
git pull --rebase origin master
From github.com:sky1339m/NetworkGroup
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
原因:这是两个不同的项目,要把两个不同的项目合并
解决:git pull origin master --allow-unrelated-histories
( i 编辑模式 ESC-->退出vim :q!)
没有ssh 不提醒密码
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
原因:权限不够
解决:1.配置ssh 2.
网友评论