Can I delete my local .git repo? - ruby-on-rails

My heroku repo grew to 1.5gb, so the nice fellows at heroku support cleared out the remote heroku repo and suggested I push a fresh copy.
However, the results of du -h .git locally show .git to be 276m. And, predictably, heroku throws an error when I try to push master to it.
So, my question: can I delete my local .git folder, do git init and push to heroku? What exactly would that do?
My app's code is pushed to github - my usual workflow is:
git add .
git commit -m "message"
git push #to github
git push heroku master

Possible Problems
There are two likely reasons your repository could be larger than expected.
You have a lot of binary assets in your repository.
You have a huge commit history.
Possible Solutions
If either of these things are the cause, you have a few options. Consider the following.
If your problem is binary assets, move your assets to an external asset store (e.g. Amazon S3 or a remote filesystem). You can then remove them from your history with git-filter-branch followed by git-gc. This will slim down your repository a lot.
If your problem is a really large history, make a separate shallow clone to push to Heroku. For example:
git clone --depth 1 my_repo heroku_repo

Well, you couldn't do that, unless you force a push (which is almost never recommended). This would erase your whole commit history and create a brand new repository.
But if you WANT to erase everything because of space... you can. It's just... strange.
What happens if you only push master?

You might want to do some housekeeping.

Do the upvoted answer but bear in mind that you can't push a shallow clone. Here's a follow up: Pushing to github after a shallow clone

Related

git push heroku - stop heroku pushing/uploading massive file

Having accidentally put a pretty large file which was not excluded by .gitignore in my working directory i committed my changes, pushed up to github then did a git push heroku up to production.
when i saw it was trying to push 100s of MB of data up to heroku, i killed the process.
I have since done a
git rm filename.extension
followed by
git add ., a new commit and git push. But when i get to git push heroku it insists on continuing to push this impossibly large data file.
how can i check what the offending file is, and how can i make git/heroku forget it was ever there so git push heroku can start working again...?
Thanks!
If you did a git rm large.file, the commit introducing the large.file is still in the history of your repo.
To make git forget about the commit, you'll need to remove it from your repo's history. This could be done using git rebase as described in the answers to these questions (for example):
How do you remove a specific revision in the git history?
How to remove selected commit log entries from a Git repository while keeping their changes?
After you removed the commit from the history, you could git push -f github and then git push -f heroku.
Note that git push -f could cause problems if someone fetched the state of your github repo since your last push. See chapter The Perils of Rebasing in the progit book for an explanation why.

Heroku -- Push new content to a heroku app created from a different machine

Our team is working on an app. We have a SVN based app. We also pushed the app to heroku. The other day the app was pushed by one member of the team, and after a couple of days of work and making some updations other member wants to push his data on heroku in the same repo from another machine. How can this be done?
Please Help.
Thanks in Advance.
You need to use Git to push applications to Heroku. If your source control of choice is Subversion, then you can use git-svn to deal with a Subversion repository using Git, including pushing to Heroku.
You need to add a git remote to the Heroku Git URL. You can find this URL in your Heroku account at heroku.com.
# stuff about setting up git-svn
$ git remote add heroku #{heroku_git_url}
$ git push heroku master
As another commenter mentioned, you will also need to manage SSH keys. The user doing the pushing will need to have an SSH private key (you can look up ssh-keygen) and will need to have the SSH public key uploaded to Heroku (heroku ssh subcommand).
So if your app is deployed and you already have a working copy. And you need to push changes.
You only want the repo with no content.
git clone --no-checkout git#heroku.com:<your-app-name>
That will clone the repo into a directory named your-app-name, and in that directory will be the repo you want. Move that .git file next to your .svn file.
mv <your-app-name>/.git ~/Code/<your-working-copy>
rm -rf <you-app-name>
You can rename the origin remote to heroku if you want. Otherwise just
git commit -am "Deploying v1.2"
git push

Setting up Github on a new computer

I am an almost perfect beginner at Github so please humor me with this elementary question.
I have a laptop PC that I've been using to interact with a repo on Github. I just bought a Mac and I would like to do my programming on both machines.
I have installed Git on the new machine and I have set up my username, e-mail, and Github token on the Terminal.
What are the basic commands I need to do this:
Download the repo from Github the first time? I've created a new folder on my Mac but going there and typing git pull git#github.com/sscirrus/repo.git produces fatal: not a repository (or any of the parent directories): .git.
Upload those changes again such that the main repo is updating cleanly with each new push. I assume that once I have the code in my new folder, it would be a matter of git add . and git push with password entry?
I am reading through tutorials on Git but just want to make sure I'm doing something sensible for my situation before my newbieness screws up a lot of prior work. Thank you!
Go through this book, http://progit.org/book/ and http://gitcasts.com/ for video tutorial.
And I recommend you follow these steps
Clone the repository (git clone repoAddress)
create a new branch (git branch branchName)
checkout that branch (git checkout branchName)
make changes and commit in that branch (git add files)
checkout master (git checkout master)
perform a pull (it updates the local repository with the remote one) git pull
If there is change, checkout the branch and rebase it with local master
If there is conflict resolve it and add that file and make a commit again
checkout master again and merge the branch (git merge branch)
push the commits to the remote repository.(git push)
If you want a GUI tool, then there is GitX which is made for Mac OS X. http://gitx.frim.nl/
Download the git repo for first time - do a clone of the repo first. this will bring your code from github to your machine for the first time.
git clone your_git_repo_url
from second time, you can
git pull your_git_repo_url
Upload the changes after commits
git push your_git_repo_url
Please read scott chacons git books. these will get you the basics of git. and learning this will help in the long run.
You need to use git clone, not git pull.
You'll want to git commit after add and before push. add just adds something to the index (Worst name ever. The "index" is essentially a pending commit.) and commit actually commits it to your repository. push then pushes committed stuff from your local repository to a remote repository.
Whilst there's a lot to be said for using git from the command line (to help understanding) you might like to try the github clients (for mac & windows - download them from the github homepage - at the bottom in the section marked 'clients') which I'm guessing might not have been available when you posted your question.
The Windows one lets you specify a default storage directory (where it clones the repos into) - the Mac one prompts you with each clone as to where you want to stick it.
Both very easy to use to do what you want (clone, pull, push etc and also good for seeing what branches you have and changing between them)

Git + GitHub + Heroku

I am new to the world of Git, GitHub and Heroku. So far, I am enjoying this paradigm but coming from a background with SVN, things seems a bit complicated to me in the world of Git. I am facing a problem for which I am looking for a solution.
Scenario:
1. I have setup a new private project on GitHub. I forked the private project and now I have the following structure in my branch:
/project
/apps
/my-apps
/my-app-1
....
/my-app-2
....
/your-apps
/your-app-1
....
/your-app-2
....
/plugins
....
I can commit the code in my Fork on GitHub from my machine in any of the folders I want. Later on, these would be pulled into the master repository by the admin of the project.
2. For every individual application in the apps folder, I have setup an app on Heroku which is a Git Repo in itself where I push my changes when I am done with the user stories from my local machine. In short, every app in the apps folder is a Rails App hosted on Heroku.
Problem:
What I want is that when I push my changes into Heroku, they can be committed into my project fork on GitHub as well, so, it also has the latest code all the time.
The issue I see is that the code on Heroku is a Git Repo while the folders which I have on GitHub are part of a Repo.
So far, what I have researched is that there is something known as Submodule in the Git World which can come to the rescue, however, I have not been able to find some newbie instructions.
Can someone in the community be kind enough to share thoughts and help me to identify the solution of this problem?
The idea behind submodules is that they're all separate git repositories that you can include into a master one and rather instead of including all the files it includes a link to that submodule instead.
How to use submodules
To use a submodule, first you must extract out the directory and create it as its own git repository by using git init. Then you can upload this separately to Github or [place of your choosing] and to use it as a submodule use the command: git submodule add [place/to/put/it] git://github.com/you/proj1.
Separation is best
I would think it better to leave these separated out as their own git repositories and push to heroku from each one. The reason? It's more likely (I feel) that you're going to be working on one at a time and doing a git commit and git push heroku master for that one only.
If you wished however to deploy all applications at the same time you could recurse down the directory tree using this Ruby script placed in the top-level directory:
Dir["**/*"].select { |dir| File.directory?(dir) }.each do |f|
Dir.chdir(dir) do
`git push origin master`
`git push heroku master`
end
end
Of course this would only work if you have staged all your changes. I can't think of a way to automate that as Ruby <= 1.9 doesn't have the module to read your thoughts.

Transitioned from Subversion to Git, how do I push to heroku gracefully?

I had been using a Subversion for my source control, combined with git ONLY to deploy (push) to heroku. My pattern was: Update local working copy from latest master at remote subversion repository. Then do git commit and git push heroku (Git was set to ignore .svn stuff). This working copy I only used to push to heroku, I had another subversion folder for doing live development, and committing to the remote subversion repository for tracking.
I have now switched to git fully. I did a complete import from subversion into a new remote git repository. I've successfully been working on my local working copy of the git repo (origin), and pushing changes when it suits me (also collaborating with one other developer, but I basically run the operation).
MY Question:
I would now like to return to my OTHER git working copy that I had previously been using to push to heroku (that has .svn/ stuff in it as well). I'm thinking of just adding my new git repository as an [origin] entry in the .git/config.. pulling the latest changes from my new git remote, and pushing to heroku, but I'm wondering if it will freak out.
It will try and merge and get confused won't it? AND, even if the pull worked, will the heroku remote get confused about a push that originated from some new git repo?
I could clobber (delete) that working copy (used to push to heroku from subversion), and make a new clone of my new git repository, then add heroku to the .git/config. But I'm concerned pushing to heroku will still cause it to get confused, since I used to push from a different working copy.
Any advice would be great!
Thanks in advance!
If I understand you correctly, you want to switch back to the former SVN repository as your working copy, and you want to preserve the old SVN history?
There are a couple of options available.
Push the recent changes from the new Git repository to Heroku, then switch to the old repository and pull from Heroku. This will bring you old repository up to date.
Temporarily change the URL in the old repository's config file to point to the local path of the new repository. Pull the recent changes from there, and then revert back to the Heroku URL when done. This will also bring your old repository up to date.
The first option is the most expedient, and the second is the long way round. Either way, you will have the same net result of an up to date local repository containing all history. The surplus new repository can be disposed of in either case.
Edit:
To address your concerns about whether Heroku will care about the origin of the commit, in brief, no the repository on Heroku is another git repository that accepts commits from authenticated users.
As long as the credentials are correct, the originating repository does not matter. This is the beautiful thing about DVCS - there is not one controlling or corruptible repository - It is entirely possible for you to now clone from Heroku on another machine and continue work from there. As long as your credentials are the same, the history will show any and all commits you push, but does not care where from.
If your desire is to simply use a clean repository to work with, the new one will be the favorite. The old one can be deleted without ill effects.
To prove this - check the SHA-1 hashes for a commit in both new and old repositories, and you will see they are identical. The hash is unique for all commits, and can be used to check the code integrity at all times. There will never be more than one change for any given hash.
As a side note, the repository is portable in that it is entirely self contained, and can be moved around freely on your storage space, or even be used on external storage such as a USB thumb drive.

Resources