git将本地文件推送到远程仓库

1.初始化项目

git init

2.建立本地仓库和远程仓库的连接

git remote add origin 远程仓库URL

ps:移除git仓库连接可使用 git remote  remove origin

3.将码云上的仓库pull到本地

git pull origin 分支名称

4.创建并切换分支,这里和远程仓库的分支要一致(选择指定推送的分支,使用git branch可以查看分支)

git checkout -b 分支名称

5.将文件加载到暂存区

git add .

ps:add错了可以使用git rm --cached 文件名 删除对应的文件

6.将文件提交到本地仓库(-m 描述信息)

git commit -m "上传说明,资源描述"

7.将本地仓库推送到远程仓库

git push origin 分支名称


yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload
$ git init
Initialized empty Git repository in D:/myProject/IJProjects/git-upload/.git/

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git remote add origin https://gitee.com/jiang-bing-yang/myprojects/tree/ewell

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git pull origin ewell
remote: [session-18405e8e] 404 not found!
fatal: repository 'https://gitee.com/jiang-bing-yang/myprojects/tree/ewell/' not found

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git pull origin master
remote: [session-804441a1] 404 not found!
fatal: repository 'https://gitee.com/jiang-bing-yang/myprojects/tree/ewell/' not found

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git init
Reinitialized existing Git repository in D:/myProject/IJProjects/git-upload/.git/

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git remote add origin https://gitee.com/jiang-bing-yang/myprojects/branches/ewell
error: remote origin already exists.

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git remote remove origin

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git remote add origin https://gitee.com/jiang-bing-yang/myprojects/branches/ewell

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git pull origin
remote: [session-ca423186] 404 not found!
fatal: repository 'https://gitee.com/jiang-bing-yang/myprojects/branches/ewell/' not found

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git remote remove origin

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git remote add origin https://gitee.com/jiang-bing-yang/myprojects

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git pull origin ewell
remote: Enumerating objects: 35, done.
remote: Counting objects: 100% (35/35), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 35 (delta 10), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (35/35), 7.51 MiB | 1.04 MiB/s, done.
From https://gitee.com/jiang-bing-yang/myprojects
 * branch            ewell      -> FETCH_HEAD
 * [new branch]      ewell      -> origin/ewell

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git branch
* master

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (master)
$ git checkout -b ewell
Switched to a new branch 'ewell'

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (ewell)
$ git branch
* ewell
  master

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (ewell)
$ git add .
warning: in the working copy of 'ewellMqSdkDemo/EwellMQ/SDKConfig.properties', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'ewellMqSdkDemo/EwellMQ/out/artifacts/EwellMQ_jar/SDKConfig.properties', LF will be replaced by CRLF the next time Git touches it

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (ewell)
$ git commit -m "ewell sdk java demo"
[ewell 1a478cd] ewell sdk java demo
 23 files changed, 387 insertions(+)
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/.gitignore
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/artifacts/EwellMQ_jar.xml
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/compiler.xml
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/encodings.xml
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/libraries/MQSDK_JAVA.xml
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/misc.xml
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/modules.xml
 create mode 100644 ewellMqSdkDemo/EwellMQ/.idea/runConfigurations.xml
 create mode 100644 ewellMqSdkDemo/EwellMQ/EwellMQ.iml
 create mode 100644 ewellMqSdkDemo/EwellMQ/SDKConfig.properties
 create mode 100644 ewellMqSdkDemo/EwellMQ/lib/MQSDK_JAVA.jar
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/artifacts/EwellMQ_jar/EwellMQ.jar
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/artifacts/EwellMQ_jar/SDKConfig.properties
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/artifacts/EwellMQ_jar/lib/MQSDK_JAVA.jar
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/artifacts/EwellMQ_jar/running.properties
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/production/EwellMQ/META-INF/MANIFEST.MF
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/production/EwellMQ/com/yjb/test/MyException.class
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/production/EwellMQ/com/yjb/test/MyTest$1.class
 create mode 100644 ewellMqSdkDemo/EwellMQ/out/production/EwellMQ/com/yjb/test/MyTest.class
 create mode 100644 ewellMqSdkDemo/EwellMQ/running.properties
 create mode 100644 ewellMqSdkDemo/EwellMQ/src/META-INF/MANIFEST.MF
 create mode 100644 ewellMqSdkDemo/EwellMQ/src/com/yjb/test/MyException.java
 create mode 100644 ewellMqSdkDemo/EwellMQ/src/com/yjb/test/MyTest.java

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (ewell)
$ git push origin ewell
Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (30/30), done.
Writing objects: 100% (41/41), 7.51 MiB | 753.00 KiB/s, done.
Total 41 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.3]
To https://gitee.com/jiang-bing-yang/myprojects
   1446d31..1a478cd  ewell -> ewell

yjb@yjbcomputer MINGW64 /d/myProject/IJProjects/git-upload (ewell)
$

常用命令
1.从远程仓库克隆项目到本地
git clone  项目地址       

2.初始化本地仓库.
git init             # 创建本地仓库

3.本地仓库与远程仓库关联.
git remote add 仓库名 仓库地址    #  仓库名自定义 例如:origin

4.查看仓库名.
git remote          # 查看远程仓库的仓库名,加-v 查看仓库名和地址

5.更改远程仓库地址.
git remote ser-url 仓库名 仓库地址  

6.将文件添加添加到暂存区.
git add .    # . 代表所有,可以指定为具体文件 

7.将暂存区中的文件提交到本地仓库.
git commit -m "注说明"

8.查看所有分支.
git branch        # 查看本地分支,加-a查看本地分支和远程分支,结果列表中前面标*标识当前使用分支.

9.创建分支.
git branch 分支名称  

10.切换分支.
git checkout 分支名称

11.将本地仓库的文件推到远程仓库.
git push 仓库名 分支名称   # 推送时建议先(pull)更新一下

12.将远程仓库更新到本地.
git pull 仓库名  分支名称  

13.修改远程仓库名称
git remote rename 旧名称  新名称

14.查看提交记录
git log   

15.回滚提交
#Reset会把后面提交的记录直接删掉
git reset --hard commithash       # 例如:git reset --hard 7b8bcaa0b02959126b923fe554824fa9df1dfd87

16.分支合并到主分支上
git merge 分支名称


常见错误
1.提交缓存区中内容到本地仓库
1.1.报错信息如下:
D:\xx\xx>git commit -m"初始化"

*** Please tell me who you are.

Run

     git config --global user.email "[email protected]"
    git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'admin@DESKTOP-NHBTH4U.(none)')

1.2.报错原因:
出现错误的原因是因为无用户信息
1
1.3.解决方案:
# 1.添加你的邮箱
git config --global user.email "[email protected]"
# 2 添加你的昵称
git config --global user.name "name"

2.本地仓库提交至远程仓库时
2.1.报错信息如下:
D:\xxx\xxx>git push origin master
To https://gitee.com/xxx/xxx.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/xxx/xxx.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.

2.2.报错原因:
    出现错误的主要原因是gitee中的README.md文件不在本地代码目录中

2.3.解决方案:
# 1.合并代码
git pull --rebase origin master
# 2.再次提交
git push origin master
 

你可能感兴趣的:(git,github)