我记得前一阵时间想使用 Git 通过命令行来新建一个远程仓库,但是始终不成功,不知道是操作不对,还是 压根不支持这样的操作呢。
我觉得如果真是不支持这样的操作的话,这个其实挺尴尬的。。。。这个功能真的很有必要啊,我们真的没有必要非得打开网页来创建。
我把错误提示搜索了一番发现这个问题挺好解决的,不过呢,试验多次,失败而终。
如果有时间我在好好琢磨一下这个问题,这里记录的不是很详细,问题也似乎描述清楚,不过,我会记着的,嘿嘿。。。。。
这个问题现在还是没解决,但是今天[27 Oct., 2016]试验了一下还是不能在本地建立远程仓库,只能是网页上建立了仓库,然后在本地的话可以新建一个 文件夹之后选择 push 到这个远程地址上面去。简单记录一下这个过程中用到的命令。
- 网页上建立仓库(略),假设此时我们生成的仓库地址是
https://git.oschina.net/markhan/demo.git
- 选择或新建本地文件夹文件夹名称随意假设这个目录称做
mainfolder
,使用git init
对文件夹进行 git 初始化,此时会生成.git
子目录 - 编辑或移入要加入仓库的文件或者文件夹至此目录, 假设我们分别放入了 文件
file1.tex
和file2.tex
,以及 文件夹folder1
和folder2
- (optional)编辑
.gitignore
文件 - 使用
git add
选择我们要推送到远程仓库的文件(夹),例如 文件file1.tex
以及文件夹folder1
,键入命令为:
git add file1.tex
和git 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)
λ
网友评论