3

I am zero in git. Absolute zero. So there are many materials and hints on the web, however I cannot put them together.

So could some one please tell me what I have done wrong and what else I should do to achieve what I am looking for?

What I want to do is simple. I have written a project in C++ and now I want to make a local repository to have version control of all my changes. That is all I need.

I have a folder:

~/myproject

which contains my project files. and another folder to save changes inside (my local place to store changes)

~/my-local-repository

So, first of all, I have set up a repo:

cd ~/myproject
git init

then I created a .gitignore :

cd ~/myproject
touch .git/.gitignore

and excluded my bin directory.

then I added a few files

git add this that

then I removed them

git reset

and again added some files. I changed some files and commit:

git commit -am "new change"

Then setting a dummy username and email:

git config user.name "my.phd"
git config user.email myphd@exmaple.com

Then I set the local repository folder for local changes:

git remote add local ~/my-local-repository

so I expect all my changes go here.

Now, when I push:

git push local

I get this error:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

fatal: '/media/doc/my-local-repository' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Maybe this error is very simple to many people. But I understand nothing out of it. What have I done wrong till now and how to fix?

ar2015
  • 4,338
  • 4
  • 36
  • 83

2 Answers2

1

The error is on the line

'/media/doc/my-local-repository' does not appear to be a git repository

That folder doesn't have a git repo in it. You need to run

git init

in it. If you are working in a new local branch, you will also have to push that new branch upstream to have it appear in the remote. To do that, see this question.

Community
  • 1
  • 1
tom
  • 2,115
  • 1
  • 14
  • 29
  • just want to make sure. `git init` must be run on the source code folder or the storage folder? – ar2015 Mar 02 '15 at 14:26
  • @ar2015: Both. Both folders need to be git repositories – tom Mar 02 '15 at 14:26
  • i did that on both. this time i got this error `No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master'. fatal: The remote end hung up unexpectedly error: failed to push some refs to '/media/doc/my-local-repository'` – ar2015 Mar 02 '15 at 14:31
  • You still need to push your current branch upstream. See the link I posted. – tom Mar 02 '15 at 14:32
  • seems worked. did it? i still did not understand what happened. [message](http://pastebin.com/jRJSZZij) – ar2015 Mar 02 '15 at 14:41
  • @ar2015. It worked. Git requires local and remote repositories to be git repositories. Individual branches created in a local repo will not get pushed up to the remote ones by default. You need to specify that you want the new local branches to get pushed up. – tom Mar 02 '15 at 15:24
  • If it has worked, is there any explanation for why i cannot see any commit in the list of Git-Cola? – ar2015 Mar 02 '15 at 22:01
  • I think I have realize it. The reason is maybe I should use Git Dag interface. thank you. – ar2015 Mar 03 '15 at 05:12
0

git push local master (or, instead of master, the branch you want to push)

If you only did git init on the other repo, it has no branches yet. So, no branch could be tracked (allowing just git push local).

After this command, you need not master at the end, because master now exists on local.

Jean Waghetti
  • 4,571
  • 1
  • 16
  • 28
  • should i use `git init --bare`? – ar2015 Mar 02 '15 at 14:48
  • It is recommended (but not mandatory) that only bare repositories accept pushes. The log tells you how to do it. But I recommend only pushing to bare repositories (created with `git init --bare`). – Jean Waghetti Mar 02 '15 at 16:14