Accidentally created a git submodule - ruby-on-rails

So I was developing a API Client gem, which was working great, had it's own github repository and my team lead decided that he wanted me to move this client api into the api repository itself. So I copied the files over into it's own directory, removed the .git directory from the client's directory, and merged it into master. Worked great.
However, now when I try to create a branch off of master, the directory shows up a submodule on github, and isn't tracked in my local git. There is no .gitmodules folder, and no mention of submodules whatsoever. I can't create a new branch because it says that there are untracked files that will get overwritten (all the files in my client gem directory) but as far as I can tell there's no way for me to start tracking these files. I can access the directory just fine, but as soon as I modify a file, the change doesn't show up in the api projects git.
What do I do?

If there is no .git folder or file in that subfolder, all you need to do is git rm --cached [folder] followed by git add [folder]/*

Running git rm --cached --ignore-unmatch client then allowed me to git add client/

Related

how to add existing non-git project to bitbucket

I created a project using angular cli. Project is in directory dw-ng2-app and it has several files generated by angular cli. I want to create a Bitbucket repository for this. My confusion is, when I create a repository in Bitbucket, it gives me 3 options
I create a README and .gitignore file. I cannot use this option as
then when I try to sync the local project with repository, I get
error that there is no common history
I selected option of starting
from scratch. The web page listed the commands I should run to clone
and upload, eg git clone git#bitbucket.org:username/angularcli.git
but this creates a new directory on my local machine named
angularcli which has .git directory. I am not sure if I can use this
option as my project is in different directory and moving it to
angularcli directory might affect it (not sure)
3rd option is to
mention that I have an existing project. Then I am prompted to use
the command git remote add origin
ssh://git#bitbucket.org/username/angularcli.git but that doesn't
work as my current project directory is not a git repository
How can I move the angular cli project to bitbucket? Should I have created the repository first and then created angularcli project in the generated directory?
There are a couple of ways to do this, but the simplest may be to simply make your current project directory, a git repository.
Go to your project directory
cd dw-ng2-app
Initialize git repository
git init .
Add your current project to be tracked
git add --all
Make your initial commit
git commit -m "Initial commit for Angular project"
At that point, you can use the third, "existing project" option within BitBucket.
After you've created a new repo there, you can see its URL and use that to track your new repository with your local one
git remote add origin https://username#your.bitbucket.domain:7999/yourproject/repo.git
git push -u origin master
[Here's a complete writeup from BitBucket if you need.][1]
note - I used git add . originally in my example, and BitBucket recommends git add --all. Either of these will work fine in your case.
[1]: https://confluence.atlassian.com/bitbucketserver/importing-code-from-an-existing-project-776640909.html
If you've created project using angulat-cli then it automatically created project with git initialisation. It also commits initial changes locally.
So you just have to add remote origin and push the content.
-If repository is not initialise as git repository then:
cd dw-ng2-app
git add --all
git commit -m "commit message"
git push -u origin master
-If already initialise with git repository.
First of all go to directory dw-ng2-app : cd dw-ng2-app
add remote to your repository.
git remote add bitbucket https://username#your.bitbucket.domain/yourproject/repo.git
push the changes:
git push -u origin master
here's master is name of branch in which you want to push the content.

How can I un-nest a Git repository

I accidentally did a git.init on a parent folder of my app (Rails project). I didn't realise until a long way into my development when I now wish to deploy to Heroku.
My folder structure is ~/project/project/app with git initialised in ~/project/app.
Heroku states:
"Heroku apps expect the app directory structure at the root of the
repository. If your app is inside a subdirectory in your repository,
it won’t run when pushed to Heroku."
So, I'm trying to undo this, without much success.
I tried moving all the folders of my app up a level, so from project/ I did the following command:
mv project/* project/.* .
This seemed to move a copy of everything up a level, into my ~/project folder, however, in terms of Git, only the still nested files (in ~/project/project/) are the branch specific files (as tested by switching branches and looking at both sets of files in my text editor).
I copied the files when my git branch was specified as the master branch. Does this mean I've only copied the "master branch" files. This is where my knowledge of git is limited.
Any help much appreciated.
** note, i have a copy of my folder or can re-clone from github.
If you don't have a problem to re-publish your repo (git push --force, meaning you will change the history of commits, and other will have to fetch and reset their local branches), you can refer to "How can I move a directory in a Git repo for all commits?".
Use git filter-branch in order to affect all commits of all branches:
git filter-branch --tree-filter \
'test -d project/app && mv project/app . || echo "Nothing to do"' HEAD

How to set up a new workstation after adding .gitignore to the repo

I have a deployed rails website, and have a gitignore file in place. If I pull the app to a new computer or workstation, none of the gitignore files will be there since they are being igrnored. How do I correctly set up a new workstation? Do I just copy the files from another location and place them in the correct folders on the new workstation?
What some like to do, including myself, is to add example configuraton to the repo. For instance, you'd add database.yml to the gitignore so that nobody commits their personal passwords and then create a database.example.yml file that contains an example of how to set up database.yml
If those files you specified in the .gitignore are an essential part of your website configuration, they should be in the repository and not ignored.
You have several options:
Ignore files for everyone cloning the project
This is done using the file .gitignore in any folder of your git repository (people usually use one .gitignore at the root folder of the repository). The "ignore-behaviour" will be transmitted to everyone cloning or pulling the repository if you run git add .gitignore, commit and push.
Ignore files only for you, and only in this repository
This is done by using the same syntax as in the .gitignore, but in the file .git/info/exclude. The "ignore-behaviour" won't be transmitted to anyone, and only applies to you and to this specific repository.
Ignore files only for you, for all of your repositories
You can do this by defining a user .gitignore with
git config --global core.excludesfile ~/.gitignore.
Ignore files for all users on this computer, and for all of the repositories
You can do this with a system-wide .gitignore: sudo git config --system core.excludesfile /etc/gitignore
I personally intensively use 1 and 2 (the file .git/info/exclude can really be useful sometimes), but never the 3 and 4.

Starting over with Git

I decided to learn how to use Version Control over Christmas break, so I downloaded Git, opened a GitHub account and started reading the online tutorial linked to from the GitHub website. When I got to this part http://progit.org/book/ch2-2.html I got stuck because I wasn't sure how to add files. For instance, I tried
git add C:/Finish.txt
And it said
Fatal: 'C:/Finish.txt' is outside repository
I was confused until I remember that a long time ago I had tried teaching myself Ruby on Rails and played around with Git back then. It never really went anywhere, but there's all this residual stuff floating around my system and I don't know how to change it. For instance, my Untracked files (which should be empty) are rails_projects/ and sample/.
How can I just erase all the old stuff and start over?
You should make a folder for your repository, move Finish.txt to that repository, then do git add.
For example:
# here you create C:\myrepo
cd C:\myrepo
git init .
# here you edit C:\myrepo\Finish.txt
git add Finish.txt
git commit -m "Added Finish.txt"
Start a new repository, e.g.
c:
md c:\newrepo
cd c:\newrepo
git init .
copy \Finish.txt .
git add Finish.txt
git commit -m "started over"
I strongly recommend against adding anything to C:\, let alone putting a git repo there. Unless of course you want to accidentally add all of your system disk to git :)
I can also heartily recommend using TortoiseGit which has some excellent explorer integration.
Delete any .git folder that you find in your drive.
To create a repo go to a folder that you want the repo in ( and not just randomly), do:
git init
Then proceed... Add only files that you put within this repo and not randomly from some location.
It would be very unusual to have the root directory of your hard drive be a git repository. That's probably why it's giving you the error.
git repositories are typically in a subdirectory and that subdirectory is typically a project.
To initialize a subdirectory as a git repository, you'd do:
git init (directory)
Then you'd add your files and commit.

Git not recognizing rails plugin

I installed the table_builder plugin from https://github.com/p8/table_builder, followed the directions at the bottom titled For a pre rails 3.0 table_builder: which works great.
The problem is since I checked out a branch of it, when I try to commit this to MY GIT repo, it doesnt think there are files even there.. git status diplays nothing, git add wont add the files..
Any suggestions as to how I can get this committed?
Maybe you cloned the plugin directly into your own repository and you now have the plugin repository within your repository?
A git repository will by default ignore any other repositories and their working directories that are located within it.
If so, you have (at least) two options:
Clone the plugin elsewhere, and then
copy the necessary files into your
repository
Clone the plugin into your repository
and then delete the plugin's .git
folder
There are other ways to manage this with git-submodule but I'm not an expert on that so I defer to someone with more knowledge.
Check the .gitignore file in your project root folder. If git status doesn't see the files and git add won't add them, it's most likely because they're being specifically ignored.

Resources