How can I add a folder recursively, with its subfolders and its files?
When I use git add folder_name, only that folder is getting added. git status now shows the files under the subfolders are shown as new files and untracked.
For example, in Rails application, inside the Rails project folder, there are many folders:
app
public
db
script
vendor
etc.
Is there a better way to add a rails project to git?
cd desired_directory; git add .;
Er, it looks like this was answered by Justin L. in a comment while I as typing.
Related
I made a Rails application.
Do i need to push these files to Github?
.browserslistrc
.gitattributes
.rspec
.ruby-version
The short answers are "if you want", and "there's no reason not to".
All of these files do something to make it easier to replicate your code base and setup on another machine. None of them contain secrets that shouldn't be shared.
.browserslistrc
The config to share target browsers and Node.js versions between different front-end tools.
.gitattributes
a simple text file that gives attributes to pathnames.
These attributes affect how the contents stored in the repository are copied to the working tree files when commands such as git switch, git checkout and git merge run. They also affect how Git stores the contents you prepare in the working tree in the repository upon git add and git commit.
.rspec
Read command line configuration options from files
.ruby-version
Many Ruby (or Rails) projects will include a simple .ruby-version file, which simply specifies a version number
I am using git with Xcode but when i commit files using Xcode (not command line) after committing and pushing to remote, when i use git status this is the result.
What are Untracked Files. What should i do with them?
And what about Changes not staged for commit part? What are they?
These untracked files are files that have been added to your directory structure (e.g. it would appear that you did a pod install), but you have neither added them to source control nor told git to ignore them. (I would tell git to ignore them, personally.)
But you have to decide whether you want to add the Pods directory to your repo or whether you'd like to ignore them. See https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control. (I personally don't put Pods into source control, just the Podfile and Podfile.lock. There are many opinions on that topic, though.)
Re the .DS_Store, we often have a ~/.gitignore_global that tells it to ignore those, too. Once you tell it to ignore these, they will be removed from the “untracked” files list. See .gitignore all the .DS_Store files in every folder and subfolder.
Re the unstaged .DS_Store it looks like your repo already had that one .DS_Store in the repo. I would suggest removing it from the repo. See How can I Remove .DS_Store files from a Git repository?.
In short, it looks like you have a project with no .gitignore file (or it is missing entries). It also looks like you don’t have a ~/.gitignore_global to ignore .DS_Store files.
For an example of a .gitignore that you might use for Swift projects, see https://github.com/github/gitignore/blob/master/Swift.gitignore (though, like I said, I generally would uncomment the Pods from that particular .gitignore).
I had not heard of this file until I randomly checked git status in an old repository and there it was, a file I had not edited myself nor ever seen before. I do not know how it got there.
It seems it's common asked about - mostly how to remove it (e.g. here and here).
What is this file, and what created it?
.idea is the dir for saving the project configurations for all Jetbrains IDES (RubyMine , Pycharm , PHPStorm , WebStorm ..etc)
you can handle it using two ways if you don't want to commit it to the repo
Ignore it only for yourself
in .git/info/exclude
add /.idea
Ignore it in .gitignore so it will be ignored for everyone who uses the repo
by adding /.idea to .gitignore
if the dir .idea already tracked by git you will need to remove it first from the cached files before ignoring by git rm -r --cached .idea
This folder can include important configuration if you did any custom configuration for the project and also include the indexed data for the IDE which helps it to provide quick autocomplete and in certain cases would be better to commit it to the repo but I always ignore it because the other developers in the team don't use RubyMinee
I'd like to split up rails using a git submodule, which as far as I can tell, works basically like a directory. While this works well with a file structure similar to Python's Django, where each module has a models.py, views.py, etc, this doesn't appear to work so well with rails, which gives you a directory structure where there is a views folder, a controllers folder, etc, with each folder having 1 file from the module.
Is there any way to convert to a file structure similar to Django's, or if not, how would you use git submodules with rails?
how would you use git submodules with rails?
You would not use them, not directly at least. A git submodule is a repo, checked out in its own folder.
If you couple it with a deployment script which would linked (symlink) files from the rails directory structure to the files from that submodule folder, then you could get a rail app.
So, I'm a newbie at git, but I'm using it because I have my rails app deployed through heroku. My app generates a bookmarklet (which is just a js file) for each user upon sign-up. Unfortunately, when I deploy, all of the bookmarklets for the users on the live site get overwritten with the bookmarklets for the users on my dev environment. I've read some other questions about this kind of thing, and I know I'll have to add the bookmarklet folder to the .gitignore file, and something about rm --cache (but I'm not sure exactly what I'll have to do). I tried doing these things, but I'm wondering if the problem is that git is ignoring all of the files that are there now, but isn't ignoring the ones that are generated after doing the whole gitignore process. Either that or I'm just doing it wrong (this is very, very likely).
Any help is welcome. And sorry that this covers the same ground as a lot of other similar questions. I did as much research as I could.
Thanks.
Here some simple steps:
Create a file .gitignore in the root of your repository, with the following simple content:
/path/to_your/folder
Add the file to your repository:
git add .gitignore
Remove the folder from your repository (this won’t physically delete the folder):
git rm --cached /path/to_your/folder
Commit
git commit
After that, the folder should be removed from your repository and subsequent changes in it will be ignored by git.
Sounds like Heroku is cleaning out every file not checked in to your Git repository when you deploy. Modify your app to save the bookmarklets to a directory outside of your Git repository.
#poke's answer is mostly correct, but the leading slash in the path name is problematic so I'm posting revised instructions.
The following steps assume the subdirectory inside your git repository is named foo.
Make sure you're at the top level of your Git working directory:
cd "$(git rev-parse --show-toplevel)"
Add foo to your top-level .gitignore file:
echo /foo/ >>.gitignore
The leading slash says to ignore foo in the top level but not */foo or */*/foo, etc. The trailing slash says to ignore foo if it is a directory, but not if it is a file or symbolic link.
Stage the newly modified .gitignore:
git add .gitignore
Commit:
git commit -m "Add foo to .gitignore"
Stop tracking the contents of the foo directory in the Git repository:
git rm -r --cached foo
The --cached option tells Git to not delete the foo folder from your working directory.
Commit:
git commit -m "Remove the foo directory"
Add the following to your .gitignore:
path/to/ignore/**/*
If there are already tracked files on that path, they won't be ignored.
You'll have to run
git rm -r --cached path/to/ignore/