How to push existing source code to a repository in github? - ruby-on-rails

I have a rails app hosted on heroku and i want to push the code to github(Aready created a repo on there).I tried to follow the steps in this question .Since i already have a local repository and currently can push and pull from heroku i skipped step 2 and 3 .But when i do step 4
git remote add origin git#github.com:sparkz19/stark-journey-1727.git
It says
fatal: remote origin already exists.
And when i do git remote -v
It says
origin git#heroku.com:stark-journey-1727.git (fetch)
origin git#heroku.com:stark-journey-1727.git (push)
What do i need to do here?Thank you in advance.

Git complains because origin is already defined. If you still want to keep the heroku remote you could use git remote rename to save it as another remote:
git remote rename origin heroku
Reset the url with git remote set-url:
git remote set-url origin git#github.com:sparkz19/stark-journey-1727.git
Now you can push and pull to any you like:
git pull heroku master
git push origin master

Just give your new remote a different name than origin and you'll be good to go.

Related

git push not working on a bitbucket repository

I've just created a repository on my Bitbucket account. I have a code already written in my laptop.
Here's the command I executed on my terminal:
git init
git add --all
git commit -m 'Initial commit'
git remote add origin https://<repo_owner_name>#bitbucket.org/<teamname>/<reponame>.git
git push origin master
I got the following error:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://bitbucket.org/EtienneVergne/disney-app-proposal.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
I've tried several git pull as suggested in the message with no sucess.
Can somebody help me ?
It's because the remote repo and your local repo are not in sync.
See what the error logs hints
Do this:
git pull origin master
git push origin master
or
git push -f origin master to override remote changes.

Why can't I see my remote git repositery?

Here is what I did:
Created a Ruby on Rails app.
Initialized empty git rep
Made changes to my app and saved them (git add -A and git commit -m "blahblah")
Deployed to Heroku.
But when I visit git hub it shows zero repos?
What did I do wrong?
I think you confound github and heroku.
It's two differents repository.
Deploying to heroku with something like this:
git push heroku master
does not affect your github account.
You can have several repository for the same project.
To add a repository:
git remote add NAME_OF_YOUR_REPO URL_OF_YOUR_REPO
(you can create a project in github, and they will git you a URL_OF_YOUR_REPO)
example:
git remote add origin https://github.com/user/repo.git
after you can do:
git push origin master
and you will see your commits on github.

heroku staging - not able to push

I am not able to push to staging for heroku.
When I am doing git remote staging master I am getting
fatal: 'staging' does not appear to be a git repository
fatal: Could not read from remote repository.
Although I used to push to staging using the same command.
git remote -v
returns
origin git#bitbucket.abc/test.git (fetch)
origin git#bitbucket.org:abc/test.git (push)
I tried to add a git remote, but It created something else and when I did git push staging master, It created another url of the app instead of pushing for the earlier staging url.
I am not able to resolve this. Also I am the owner of the heroku app.
There is only one git repo configured here, and that is a bitbucket git repo. You need to add the heroku configuration too. See this link for reference.
Ultimately, run something like heroku git:remote -a heroku-app-name -r staging. Then you can do git push staging master and it'll push to the given app.

Can't push master branch to Heroku in Git

I am collaborating on a project and cloned the repo from Github, made some changes and pushed to Heroku. Now the cloned app had all of its keys and passwords hardcoded, not in ENV variables.
So I created ENV variables, added the file to .gitignore. So this app still has these keys in the commit history. What I have done now is have the author create a new repo on Github, remove .git file from original app and push new code to new repo.
So now I have cloned the new app, added a new remote the the Heroku app.
heroku git:remote -a myapplication
My issue is I cannot push the new app to the existing Heroku app. When I do I get:
error: failed to push some refs to 'git#heroku.com:myapplication.git
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
So a git pull says everything is up to date.
git remote -v outputs
heroku git#heroku.com:myapplication.git (fetch)
heroku git#heroku.com:myapplication.git (push)
origin git#github.com:author/myapplication.git (fetch)
origin git#github.com:author/myapplication.git (push)
What can I do to push the new application to the existing heroku app?
Update
I ran
git push -f heroku master
which pushed but I had error
you have not declared a Ruby version in your Gemfile.
To set your Ruby version add this line to your Gemfile:"
ruby '1.9.2'"
I've never had to specify before, and now all the original config vars that where set are no longer stored in Heroku.
git pull would pull by default from GitHub, which has all your commits already.
You might need to:
git pull heroku
clean-up the files (if the merge brings back the hardcoded values)
push to origin
push to heroku through the heroku command.
Git uses the concept of tracked branch to know which remote branch is linked to a local branch.
In your case, you probably have your local branch (I suppose it's master) linked to origin/master. So, when you do a git pull, Git is trying to get new stuff from git#github.com:author/myapplication.git, which is not the wanted behavior.
You have to change your tracked branch using :
git branch --set-upstream-to heroku/my_branch
Then, you can do a git pull which will now have the wanted behavior. Then just push to heroku, as you always do.

Issue trying to push to git repository

Problem when pushing app to github. This is what I entered into the command line. Hopefully it's just a small problem I can fix thanks.
git init
git add README.md
git commit -m "first commit"
git remote add origin git#github.com:travi5567/first_app.git
git push -u origin master
This is the error I get:
Traviss-MacBook-Pro:sample_app Travis$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
If you don't know how to use SSH keys or would rather not you can also use the https remote like so:
git remote add origin https://travis5567#github.com/travis5567/first_app.git
git push origin master
Password for travis5567: <enter your password>
# regular output from a git push
GitHub uses SSH keys to configure access to git repositories. If you are the owner you can push to the repo but you need to tell git your SSH key so they know who you are first.
It's all explained on the GitHub website - https://help.github.com/articles/generating-ssh-keys

Resources