美文网首页
建立远程仓库的方式有几种?

建立远程仓库的方式有几种?

作者: iMark | 来源:发表于2016-09-08 15:17 被阅读138次

我记得前一阵时间想使用 Git 通过命令行来新建一个远程仓库,但是始终不成功,不知道是操作不对,还是 压根不支持这样的操作呢。

我觉得如果真是不支持这样的操作的话,这个其实挺尴尬的。。。。这个功能真的很有必要啊,我们真的没有必要非得打开网页来创建。

我把错误提示搜索了一番发现这个问题挺好解决的,不过呢,试验多次,失败而终。

如果有时间我在好好琢磨一下这个问题,这里记录的不是很详细,问题也似乎描述清楚,不过,我会记着的,嘿嘿。。。。。


这个问题现在还是没解决,但是今天[27 Oct., 2016]试验了一下还是不能在本地建立远程仓库,只能是网页上建立了仓库,然后在本地的话可以新建一个 文件夹之后选择 push 到这个远程地址上面去。简单记录一下这个过程中用到的命令。

  • 网页上建立仓库(略),假设此时我们生成的仓库地址是 https://git.oschina.net/markhan/demo.git
  • 选择或新建本地文件夹文件夹名称随意假设这个目录称做 mainfolder,使用 git init 对文件夹进行 git 初始化,此时会生成 .git 子目录
  • 编辑或移入要加入仓库的文件或者文件夹至此目录, 假设我们分别放入了 文件 file1.texfile2.tex,以及 文件夹 folder1folder2
  • (optional)编辑 .gitignore 文件
  • 使用 git add 选择我们要推送到远程仓库的文件(夹),例如 文件 file1.tex 以及文件夹 folder1,键入命令为:
    git add file1.texgit add folder1 也可以一次性的使用 git add file1.tex folder1
  • git commit -m "masage goes here"
  • git push 来推送,注意我们当前是在一个未与远程建立任何关系的本地仓库中操作的,这时候使用 push 的话,git 是不知道要往哪里推送的,所以必须有地址, 此处我们使用 git push https://git.oschina.net/markhan/demo.git
  • OK,现在可以去网页上面看一下了,工作已经同步了。
C:\EndNote
λ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Jabref.lnk
        META.Data/
        META.bib
        META.enl
        Meta.bib.bak
        desktop.ini

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

C:\EndNote
λ git show
fatal: your current branch 'master' does not have any commits yet

C:\EndNote
λ git init
Reinitialized existing Git repository in C:/EndNote/.git/

C:\EndNote
λ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        Jabref.lnk
        META.Data/
        META.enl
        Meta.bib.bak
        desktop.ini

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

C:\EndNote
λ git add .gitignore

C:\EndNote
λ git add  META.bib
The following paths are ignored by one of your .gitignore files:
META.bib
Use -f if you really want to add them.

C:\EndNote
λ git add -f META.bib

C:\EndNote
λ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   META.bib

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Jabref.lnk
        META.Data/
        META.enl
        Meta.bib.bak
        desktop.ini

C:\EndNote
λ git commit -m "initial commit"
[master (root-commit) 611048b] initial commit
 2 files changed, 5396 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 META.bib

C:\EndNote (master)
λ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using


    git remote add <name> <url>

and then push using the remote name

    git push <name>


C:\EndNote (master)
λ git remote add bibmeta https://github.com/Mark-Han/bibmeta.git

C:\EndNote (master)
λ git push bibmeta
remote: Repository not found.
fatal: repository 'https://github.com/Mark-Han/bibmeta.git/' not found

C:\EndNote (master)
λ git remote add metabib https://git.oschina.net/markhan/metabib.git

C:\EndNote (master)
λ git push metabib
To https://git.oschina.net/markhan/metabib.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://git.oschina.net/markhan/metabib.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.

C:\EndNote (master)
λ git pull
fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.

C:\EndNote (master)
λ ggit pull metabib
warning: no common commits
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://git.oschina.net/markhan/metabib
 * [new branch]      master     -> metabib/master
You asked to pull from the remote 'metabib', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

C:\EndNote (master)
λ git pull metabib master
From https://git.oschina.net/markhan/metabib
 * branch            master     -> FETCH_HEAD
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

C:\EndNote (master)
λ git pull metabib master
error: Pull is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

C:\EndNote (master)
λ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both added:      .gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Jabref.lnk
        META.Data/
        META.enl
        Meta.bib.bak
        desktop.ini

no changes added to commit (use "git add" and/or "git commit -a")

C:\EndNote (master)
λ git init
Reinitialized existing Git repository in C:/EndNote/.git/

C:\EndNote (master)
λ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both added:      .gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Jabref.lnk
        META.Data/
        META.enl
        Meta.bib.bak
        desktop.ini

no changes added to commit (use "git add" and/or "git commit -a")

C:\EndNote (master)
λ git add .gitignore

C:\EndNote (master)
λ git status
On branch master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

        deleted:    .gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Jabref.lnk
        META.Data/
        META.enl
        Meta.bib.bak
        desktop.ini


C:\EndNote (master)
λ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using


    git remote add <name> <url>

and then push using the remote name

    git push <name>


C:\EndNote (master)
λ git push https://git.oschina.net/markhan/metabib.git
To https://git.oschina.net/markhan/metabib.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.oschina.net/markhan/metabib.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.

C:\EndNote (master)
λ git pull
error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.

C:\EndNote (master)
λ git pull https://git.oschina.net/markhan/metabib.git
error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.

C:\EndNote (master)
λ git status
fatal: Not a git repository (or any of the parent directories): .git

C:\EndNote
λ git init
Initialized empty Git repository in C:/EndNote/.git/

C:\EndNote
λ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Jabref.lnk
        META.Data/
        META.bib
        META.enl
        Meta.bib.bak
        desktop.ini

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

C:\EndNote
λ git pull https://git.oschina.net/markhan/metabib.git
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://git.oschina.net/markhan/metabib
 * branch            HEAD       -> FETCH_HEAD

C:\EndNote (master)
λ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Jabref.lnk
        META.bib

no changes added to commit (use "git add" and/or "git commit -a")

C:\EndNote (master)
λ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        META.bib

no changes added to commit (use "git add" and/or "git commit -a")

C:\EndNote (master)
λ git add .

C:\EndNote (master)
λ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   .gitignore
        new file:   META.bib


C:\EndNote (master)
λ git commit -m "initial commit"
[master 57cd42f] initial commit
 2 files changed, 5365 insertions(+), 32 deletions(-)
 create mode 100644 META.bib

C:\EndNote (master)
λ git push https://git.oschina.net/markhan/metabib.git
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 49.73 KiB | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://git.oschina.net/markhan/metabib.git
   2c1e765..57cd42f  master -> master

C:\EndNote (master)
λ git status
On branch master
nothing to commit, working directory clean

C:\EndNote (master)
λ ggit -help
Unknown option: -help
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

C:\EndNote (master)
λ git --help
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Reapply commits on top of another base tip
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

C:\EndNote (master)
λ git status
On branch master
nothing to commit, working directory clean

C:\EndNote (master)
λ

相关文章

  • 建立远程仓库的方式有几种?

    我记得前一阵时间想使用 Git 通过命令行来新建一个远程仓库,但是始终不成功,不知道是操作不对,还是 压根不支持这...

  • Git远程仓库地址变更本地如何修改

    作为git仓库的远程地址变了,如何配置使本地仓库和新的远程仓库建立关联呢?方法有很多,这里简单介绍几种: 以下均以...

  • VS Code中进行git远程仓库同步

    本地仓库和远程仓库建立连接 方式一:从Git远程仓库克隆:命令 git clone "SSH方式二:在本地创建一个...

  • 打通本地和远程仓库

    现在的情况是 你已经有了一个远程仓库,现在想要开发代码 如何操作建立本地和 远程的仓库 如何建立联系呢?有两种方式...

  • git同步远程仓库分支

    git命令 何谓同步远程分支?有几种情况: 本地有新分支,远程仓库没有。 远程仓库有新分支,本地没有。 本地删除了...

  • Git常用命令--了解这些就够了

    Csdn 将本地工程push到远程 方式一: 建立本地仓库 git init 创建远程仓库:在github或者gi...

  • git -refusing to merge unrelated

    主要原因:本地仓库和远程仓库实际上是独立的两个仓库。假如直接git clone的方式在本地建立起远程github仓...

  • git关联远程仓库

    如需克隆远程仓库代码 直接与远程仓库建立链接 最后提交

  • git 相关开发常用

    1、切换远程仓库地址: 方式一:修改远程仓库地址 更换远程仓库地址,URL为新地址。 2、方式二:先删除远程仓库...

  • 如何从头一个创建git仓库

    git仓库(repo)分为两部分,本地仓库和远程仓库,本地仓库是建立在本地机上的仓库,远程仓库是建立在github...

网友评论

      本文标题:建立远程仓库的方式有几种?

      本文链接:https://www.haomeiwen.com/subject/wfisettx.html