Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Newbie tip: To git init or not to git init, that is the question #564

Closed
gnagle opened this issue Jan 24, 2016 · 6 comments
Closed

Newbie tip: To git init or not to git init, that is the question #564

gnagle opened this issue Jan 24, 2016 · 6 comments

Comments

@gnagle
Copy link

gnagle commented Jan 24, 2016

This is a tip for newbies to git and github. When I first started using git on my local machine, I followed a lot of how tos which said the first thing you did to create a repository was to cd to your repo directory in a shell, and call

git init
The repo dir could be an empty directory or one fully populated with whatever you want to store in git. I then staged and committed my source code to the local git repo created with git init.

Now, I wanted to try out more git features in a sandbox environment on my own machine instead of immediately jumping to a remote server like github. In other words, I wanted to test out the commands push, pull, clone, fetch, etc. somewhere local so I could simulate working with a remote storage location. In my case the somewhere local was just another drive.

I found these directions helpful in creating a "remote" shared repository on my D drive (I confess to being a Windows developer).
http://www.gitguys.com/topics/creating-a-shared-repository-users-sharing-the-repository/

Finally, I was ready to try out github. Now here is the golden nugget for a newbie to understand. After you push your repository to your github account location, and you are ready to have another user clone it, or you want to clone it in another directory to test out some stuff, the you DO NOT RUN the git init command since git clone brings down all those git files too.

I wish the github step by step mentioned this!

@cirosantilli
Copy link
Collaborator

Please provide a link to where the instructions you want to improve are located.

@gnagle
Copy link
Author

gnagle commented Jan 26, 2016

Here are the links from github Help which describes how to create a local clone:
https://help.github.com/articles/fork-a-repo/
https://help.github.com/articles/cloning-a-repository/

This page is helpful, but it does not warn users that this should be directory where you have not already run git init.
This may be readily obvious to someone with git experience, but I am quite new to git and so I thought I needed to run git init to prepare the directory to receive the clone. Of course, I figured it out with some trial and error, but the github help page could also make reference to this fact with a note explaining what I explained in my post.

I posted this comment to your website after reviewing the Readme file in your public repository since I thought a new git and github user might find it helpful. However, if I have misunderstood the purpose of your repository, I apologize. I do not plan to post again.

Best regards,
Gail Nagle
----- Original Message -----
From: Ciro Santilli 六四事件 法轮功 包卓轩
To: isaacs/github
Cc: gnagle
Sent: Saturday, January 23, 2016 5:35 PM
Subject: Re: [github] Newbie tip: To git init or not to git init, that is the question (#564)

Please provide a link to where the instructions you want to improve are located.


Reply to this email directly or view it on GitHub.

@cirosantilli cirosantilli reopened this Jan 26, 2016
@cirosantilli
Copy link
Collaborator

I don't understand, git clone does not require git init.

@gnagle
Copy link
Author

gnagle commented Jan 26, 2016

Yes, you are correct. In fact, a git init prior to git clone will produce an error. But I did not understand that. I was following other online instructions for setting up a repository which all include the git init step. Therefore, in preparation to clone the repository residing on github to my local system, I also did a git init in the local repository directory. Then the git clone command produced errors. I was confused by this. That was the whole point of my post, explainging that one should not git init in a directory where one plans to clone another repository.

On the otherhand, if you plan to bring the repository residing on github down to your local system using git pull, you do need to have previously done git init.

To new users, and I stress the fact that this is an issue which will primarily affect new users, this is something which should be explained. For users to have confidence in a new and quite different type of source control software, like git, explaining what is going on and why, is important. When things work as expected, it builds trust. Errors produce doubt and fear that something fundamental beyond one's understand is not working.

If it is OK, I will add another post describing the different behavior of git pull to complete and better describe the point I was trying to make.

----- Original Message -----
From: Ciro Santilli 六四事件 法轮功 包卓轩
To: isaacs/github
Cc: gnagle
Sent: Tuesday, January 26, 2016 12:14 AM
Subject: Re: [github] Newbie tip: To git init or not to git init, that is the question (#564)

I don't understand, git clone does not require git init.


Reply to this email directly or view it on GitHub.

@gnagle
Copy link
Author

gnagle commented Jan 26, 2016

Just one more clarification with respect to the initialization of a local empty git repository (i.e. directory) from a remote source. The correct command here is "git clone". It is a complete copy of another repository, including the .git directory. That is why you do not do a "git init "in that empty repository since then it will no longer be empty. Indeed, running "git clone" in a directory which has a .git dir produces an error. Another way to initialize a local repository with the contents of a remote repository is to run "git pull." In this case however, you do need to run git init first because "git pull" is actually going to merge the remote repository into your existing repository. If your repository contains no other files or subdirs besides the .git directory created by "git init", then it will essentially behave as if you did a "git clone". Likewise, if your local repository contains more objects than the .git subdirectory created with "git init", then "git pull" will merge the two repositories.

There is obviously much, much more to learn about git. This is just step 1.

@S20P
Copy link

S20P commented Oct 11, 2016

Permission denied
git init not working

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants