Why is Github desktop creating a new folder rather than using the one I specified when creating a new local repo? - version-control

I am looking to do something I thought was pretty simple... I have an existing folder (with project files) on my desktop that I would like have tracked by Github desktop for purposes of source/version control. It seems straightforward... I go to github desktop, select that I'd like to create a new repository, and point it at the folder on the desktop. Here is what I expect to happen:
Desktop
Project folder
Project files
(hidden) .git folder
(hidden) .gitattributes
Instead, this is what I get:
Desktop
Project folder
Project files
New folder with specified git repo name
(hidden) .git folder
(hidden) .gitattributes
I am not sure why this is happening and it is very frustrating. It looks to me like I have only two options here:
Cut and paste Project files into New folder with specified git repo name
Cut and paste .git folder and .gitattributes out of New folder with specified git repo name and into Project folder, delete New folder with specified git repo name, remove the new repo in Github Desktop when it says it can't find it, and "Add Existing repo" in Github Desktop and point it at Project folder.
Both of these approaches sort of feel like hacks and I am not sure what consequences, if any, may negatively impact my version control intention as a result. Is this a common problem? What should I do?

I wouldn't use github desktop to make your repository. If you don't have it already try installing git bash, a command line interface, and initialize git from there.
Find your existing folder and move to it using cd <folder name here> if you go into the wrong place use cd .. to move out/back one folder
When in your folder use git init to initialize git(the version control software)
Open GitHub Desktop once again and hit "add" then "add existing repository" finally "choose" and find your file in your file explorer

When you go to "Create a new repository":
Name: New folder with specified git repo name
Local Path: Desktop (ie one level up from Project files)
This will create the .git and .gitattributes in your existing folder without affecting the other files.
The Create a new repository dialogue seems to assume the name should be used as a new folder under the path you specify.
Note that if there are spaces in your name, it tries to replace them with hyphens.

Related

Github desktop caches deleted local repository

I'm new at GitHub and I'm having this issue: I created three private repositories for my project, all fine. On the fourth one, for some reason GitHub desktop included the node_modules folder (its an angular cli app), so I deleted the repository from GitHub.com and from GitHub desktop. When I try to recreate it, it is "cached" on my Mac, even if I copy everything to another folder, and it tries to upload the node_module files.
I also changed the name of the repository, copied all the files but node_modules folder to another folder. Same happens over and over.
I couldn't find anything on internet about this. Sorry if its a newbie question.
You could try to delete the git folder that it's being hidden by default.
Go to in file explore -Views- select "Hidden Items" and try to remove the git folder from here. After that set up your .gitignore file and pass node_modules before you use git init
Use this in your terminal, if you are using VS Code use this in the same folder you are having the problem : git config --global core.excludesfile '~/.gitignore'

Why does eGit create an extra directory in the remote repo when I do the first commit/push?

Using eGit...
When I perform the initial Commit and Push from Eclipse, a new directory appears in the remote repo. Inside that directory is the root of the project directory. It makes a big mess because when someone clones it (again using eGit) the src folder is munged into a name containing then project folder name, which mucks up the package references in the class files.
eGit assumes you don't want an entire git repository for a single workspace project. Doing so would be wasteful and cumbersome for almost anything nontrivial. https://wiki.eclipse.org/EGit/User_Guide#Implications
You also didn't commit the .classpath file, which would have indicated what the source folders were.

Publishing to github results in an empty repository

I am new to git. I downloaded the desktop version (for Windows). I dragged the folder containing my project into the big window, "Get started by adding a repository." All the files showed up in the left window. Then I clicked on "Publish Repository". It then shows 143 files have changed, with 0 unsynced.
But when I go to my account on the git website, the repository is empty. The only files in it are .gitattributes and .gitignore. The whole idea here is that I want to share this project with other people.
Help out a git newbie and explain how I get the entire solution into git?
Thanks!
As you already have the remote repository at GitHub, you should use the clone option first to clone your repository locally.
This will create a folder (your repository clone) on the default location containing those two files.
Then you can copy your project files to this folder and try to sync again.

How to get src folder under project-root folder in github when staging from eclipse using egit

Current scenario :
In Eclipse when we create a project, say a PyDev project named ‘SimpleGit’, the folder structure created by eclipse will be like
EclipseWorkingDirectory/SimpleGit/src/
correct?
If we add this to git using Egit, by right clicking on the project folder SimpleGit then Team>Share, The folder structure in which repo is formed like this
Parent Folder/ SimpleGit/ .git
Parent Folder/ SimpleGit/SimpleGit/src/
And when we stage it to remote github everything will come under
Username/ SimpleGit / SimpleGit / src /
So when we look in GitHub in the root project folder (Username/ SimpleGit) we can’t see the source folder. It will be under another folder ‘SimpleGit’. How we can avoid this?
What I want is , I want to get my source forlder(src) listed under the Project Root directory, when staging from an already built project in eclipse using egit. How do I do this?
I want like this:
https://github.com/nicholasbishop/blender
Not like this:
https://github.com/afilash/SimpleGit
it cannot be done using eGit - it assumes the Eclipse project structure.
But it can be accomplished by using git itself. Just create a repository under SimpleGit folder executing 'git init'. From that point on you'd have to manage your git repository by either git itself (command line) or some other UI. SourceTree works really well for me.
It is a bit late, I know, but this method perfectly works and I hope it is useful for anyone who sees this post from now on.
The procedure is the following:
First step is creating a repository on Github (through github.com)
Move to Eclipse IDE (Git Repositories view) and click "Clone a Git Repository and add the clone to this view". Doing that the project will be somewhere located on the hard disk. Usually, it is stored in C:\Users\username\git\projectName but you are able to change it. This is our local repository.
Once done, press (in Eclipse IDE) File->Import->Projects from Git->Existing local repository(Select the one you cloned before)->Import using the new project wizard->Finish->Java->Java Project->Specify project name (just below the dialog box there is a checked checkbox that says use default location, uncheck it. Here is where you have to specify the directory you chose while cloning the repository previously).->Next->Finish
It should be enough for creating the right directory structure.

Eclipse - Exclude root directory from git repository?

I'm trying to setup a git repository for my Eclipse project using EGit. However, I'm having trouble excluding the root/project directory from the repository. That being, my project has the structure:
ProjectDirectory
src
war
etc
I would like the repository to contain src, war, and etc, but not contain the parent directory ProjectDirectory. That's because if I want to clone a copy of the project in my workspace, ProjectDirectory2, the repository for the second project now will try to create a second root directory, ProjectDirectory. Unfortunately, when I try to add a repository for a project using EGit, I seem to only be able to use Team > Share Project on the project folder itself and I don't seem to see anyway to exclude the root directory in the repository from within Eclipse.
Any suggestions on how to skip the top directory in the repository using EGit? I'd prefer being able to do everything from within Eclipse, but if there isn't a way, is there a way to setup the repository this way outside of git, then still be able to use the git control regularly from within git on the repository skipping the top level directory? Thank you much.
Short answer is It is POSSIBLE with EGIT + M2E
trick is when doing share project -> in the configure git repo window
making sure use or create repository in parent folder of project is ticked
and making sure click create repository button
the main aim of this is to create the .git folder in you project root
not above your project root.
Here's my solution. Though not particularly elegant - the steps are all simple, it works, and can be done in about 10 minutes:
Clone the remote git repo into your local filesystem .. e.g.: ~/git/project_repo_root
Create your eclipse project as usual .. e.g.: ~/workspace/eclipse_project_root
Delete the project from eclipse (but not filesystem!)
Open file manager and move the eclipse project you just created from ~/workspace/ root into ~/git
mv ~/workspace/eclipse_project_root ~/git/
Move the .git/ folder from the repo folder to the eclipse project root folder:
mv ~/git/project_repo_root/.git ~/git/eclipse_project_root
Using a shell go into /eclipse_project_root/ and do the usual command line commands for all files you want in the repo:
git add <abc>; .. commit; .. push
Return to Eclipse and go to Git Perspective, and click "Add an existing local Git repo to this view". Select the git repo you are working with and the view should be updated with an entry for that repo once you say ok.
Once you see the local repo in your view, you can right click it and select Import Projects
Go back to your main development perspective (Java, etc) and you should see the project there with the Git markup on the root node in package explorer view.
~~~~~
At that point, you should see the eclipse project folder you had just moved (to ~/git in the examples described here)
I realize this is more verbose than I would like my answers to be, but for this particular challenge/solution .. I don't know of a more straightforward way to do it.
And as for the post above that describes you should always include the eclipse project root directory .. the reality is some projects/clients/etc require that the git repo not contain the root folder. So a solution like this is necessary sometimes
You should commit the project root for multiple reasons:
If you commit only sub directories of your project, you will miss files and folders which are hidden below the project root (e.g. the .settings directory and others). Those need to be committed also, otherwise your project is going to miss information and may not lead to the same results on another machine.
Your wish of trying to clone the same repository a second time in the same workspace sounds very much like you should re-read about git branches. In git, switching between branches is done after a blinking of the eye, so branches should be used when working on different features, versions or otherwise different editions of your project.
The Eclipse project name and the underlying folder name on disk do not need to be the same (watch out for the checkbox "use default location" when creating a new project). So you can checkout a second clone of the project with a different name.
If you later add more projects to your workspace (e.g. a test project), you cannot easily share them into the same git repository, as the content of those additional projects would mix up with the sub directories of the first project in the repository.
If you have maven project you would typical like to create a repository without the project folder created by egit. For my experience this is not possible with the egit plugin.
But it can be easily done from the git command line.
First move your existing eclipse/maven project from your eclipse workspace into your git folder (this is what also the egit plugin did):
mv myproject ~/git/
next create a new git repository
cd ~/git/myproject
git init
Now create a .gitignore file and place it into your new repository folder (~/git/myproject/.gitignore). This is an example for a .gitignore file:
# ignore all bin directories
# matches "bin" in any subfolder
bin/
# ignore all target directories
target/
# ignore all files ending with ~
*~
# ignore eclipse directories and project files
.settings/
.project
.classpath
Finally initalize your new repository with the content of your project
git add *
git commit -m "My initial commit message"
Thats it.
Now you can restart your eclipse and reimport the project from your new git repository.
Go into your eclipse egit repository view and coose 'import exisiting project'.