Migrating forked project from Heroku to Github - heroku

Some time ago I found some code in one Github repo. I downloaded it (did not fork it), started upgrading it and when I was happy with the result, I used Heroku as a host. So now the code lives on my computer and Heroku. How could I push it to my Github account, but also give the original author of the project some credit for it (showing on my Github that I actually forked it)?

Okay, so I actually figured it out already!
First, create a new repository on github, let's name it github-project.
git clone git#heroku.com:<heroku-project>.git
cd <heroku-project>
git remote rm origin
git remote add github https://github.com/<github-username>/<github-project>
git pull github master
Now you'll probably see some conflicts. If you want to preserve all your changes, just add them all.
git add .
git commit -m "some message"
git push github master

This is quite simple:
Create an empty repository on GitHub, let's call it github-project
Clone from Heroku, let's call it heroku-project
Add a remote for github
Push to GitHub
The commands to perform these steps:
git clone git#heroku.com:heroku-project.git
cd heroku-project
git remote add github https://github.com/github-username/github-project
git push -u github master
That's it!
Note: if you already created the GitHub project with a README file in it, then it is NOT empty anymore, and the last push will be refused. In that case you can force the push, effectively overwriting the project on GitHub, by using the --force flag, for example:
git push -u github master --force

Related

git push to create new GitHub repo not working

I am trying to create a script that prompts for a name to give to a new GitHub repo, and then create the GitHub repo by pushing to the remote URL which the new GitHub repo will have. When I use the script I get these errors:
remote: Repository not found. fatal: repository 'https://github.com/JT-style/great.git/' not found
read -p"Enter the name of remote repository: " name
mkdir ~/rep/$name
cd ~/rep/$name
echo "#$name" >> README.md
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/JT-style/$name.git
git push -u origin main
echo "Done"
Why doesn't this work? What can I do to achieve my goal?
p.s. This is my first script.
You can't push to a repository to github if it doesn't already exist. Usually, you'd create one through a web browser by going on their site, but they released a cli called gh, which allows creating repositories (you have to authenticate somehow before though).

How to update a website deployed on heroku?

I created a website that I deployed on heroku. I have made some changes there and am looking to update my website to reflect these changes. To do this, I ran the following commands:
git status
git init
git status
git remote -v
git add .
git commit -m"The file"
git push heroku masterbranch
I want to clarify that the masterbranch branch is a branch that has been created. The base branch of my website is master not masterbranch. The reason why, I created a new branch is that when I ran the command: git push heroku master I was getting the error:error: failed to push some refs to 'https://git.heroku.com/gkwhelps.git' But I don't think that is the reason why my deployed site does not is not up to date.
This has nothing to do with Git itself. See the heroku documentation, which notes that:
Heroku only deploys code that you push to the master or main branches of the remote. Pushing code to another branch of the heroku remote has no effect.
You mention:
when I ran the command: git push heroku master I was getting the error: error: failed to push some refs to 'https://git.heroku.com/gkwhelps.git'
When you push to the main or master branch, Heroku will:
read your code;
attempt to build your code based on what it read in step 1;
attempt to deploy your build from step 3.
Any of these three steps can have errors. If they do have errors, Heroku uses Git to relay these errors to you and then tells Git to produce the above error message. So Git says that your push failed, but that's because Heroku told Git to fail it. You cannot fix this problem by creating another branch. You must address the problems that occurred in steps 1, 2, and/or 3.
If you first push your code on Github and from Github do deploy, you shoud do:
git status
git add .
git commit -m 'changes'
git push
After that you should connect Heroku with Github and do deploy from that branch from Github.

How to push a new code to an existing git repository in github

I need to push my modified new java code to my old git repository in github but I do not have old code in my pc. How to do that?
I had push a code before my github account before. Now I don't have that old code in my pc. How do I pull the project into my pc and after making changes, push again to the same repository?
I do not have much experience in github, so please help me to improve skills on github.
Check your remote first to see where it is pointing to by
$ git remote -v
origin ssh://git#<old-git-url>/<project>.git (fetch)
origin ssh://git#g<old-git-url>/<project>.git (push)
Change the pointing to GitHub
$ git remote set-url origin ssh://git#<github-url>/<project>.git
Now your repo is pointing to Github
Now you can make your changes and then add them and do a commit and finally push to remote branch; say you are on master.
git add <file>
git commit -m <commit message>
git push origin master
I had to do just that and achieved it like this.
Setup. I assume you have a new remote repository with files that may not cause a conflict with the directory you currently have locally.
Git clone from the git repository you need to push to. Just make sure you create a new directory for the cloned code.
Copy the contents of the cloned repository into the local directory that has your current code. Make sure to copy the .git (hidden) file.
cd into your local directory and run git remote -v. You should see the remote repository git address.
git add -A to add whatever change you require and commit it.
Finally git push
You need to make sure that your local repository (the one that is on your computer) is connected to the remote repository (the one that is on the GitHub servers).
After this, you need to add the modified file to the staging area. Say, you have a file test.txt that you have modified, you would add it to the staging area by typing
git add test.txt
After that you would need to commit those changes. You can do that by
git commit -m "commit message"
And that's it, you have now saved those changes and recorded them in the version control. But the changes that you made have only been recorded in your local repository and you would need to push these changes to the remote repository (the GitHub servers). You can do this by
git push origin master
It would take a few seconds (depending on your internet speed and the project file size) to push these changes to the remote servers. Once it's done, you can open that repository on GitHub and see the changes for yourself.
Just to amend this a bit. I believe "master" is now "main" in some instances or platforms. If this answer isn't working for you, try swapping that out. It worked for me.

BitBucket - error: failed to push some refs

I have some projects I would like to upload on my bitbucket private profile. I performed the following steps but I get an error.
Convert my project to git with: git init
Next:
git add
git commit -m "some message"
I created a bitbucket repository and version control system is GIT.
I then type this (of course with real account name and reponame and repo owner):
git remote add origin https://<repo_owner>#bitbucket.org/<accountname>/<reponame>.git
Finally,
git push -u origin master
I did all of this and my terminal gives me this error:
To https://bitbucket.org/milosdev_me/lfs.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://milosdev_me#bitbucket.org/milosdev_me/lfs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Try:
git push origin master --force
This works for me.
Your master branch has some code that you don't locally have, and to prevent you from conflicts, it doesn't let you to push further changes, before you have them locally. To resolve this, pull all the changes to your local repository (your project):
git pull origin master --allow-unrelated-histories
After that, you will have all the code that is available on your master branch.
NOTE: Be careful, pulling the code from remote branch might mess up all the changes locally. Make sure to save those changes somewhere, or create another branch locally where you will pull your origin master branch, so it doesn't mess up your changes.
Your issue is that you have different things between your local repository and your git repository (probably a readme file that you created automatically), so you have two options:
use git pull origin master, with this command, you will pull from your git repository, but it will cause a merge conflict, which you have to resolve using an IDE (recommended to beginners) or through cmd.
use git push origin master --force, this way, you will force your push from your local repository to your git repository, ignoring any merge conflict by overwriting data. I'm not sure, but I think it will overwrite all git repository data with you local repository data (which is what you want).
Adding --force option is a bad idea
Either rebase it or pull the code, merge it and push it.
git pull --rebase origin master
git push -u origin master
Your remote repository and local repository have differences, something new in remote repository. So for pushing you need pull changes, from remote, previously. Try do:
git pull
git push -u origin master
The issue is because your remote repository and local repository have differences.I had same issue and i tried all the above mentioned solution but nothing worked for me.
For me the scenario was :- I already had my branch in remote repository.If you have the same scenario then follow below steps:-
run command 'git pull'
delete branch from local repository
checkout that particular branch using "checkout as a new local branch" from
the Remote repository.
run command 'git branch -u <your_branch_name>'
run command 'git push or git push --force'
or you can try directly from step 4 first , if it does not work then follow entire steps.Hopefully it will help someone.
If you have your bitbucket account linked to jira.
(this answer will work for you, only if you have your jira account linked to bitbucket)
I was having the same problem trying to push my current branch with the origin.
for example:
my branch name was:
feature/PREFIX-000-new-name-branch.
previous commit:
git commit -m "Write your commit here"
so far it was not working.
you have to mentioned the ticket name in the commit.
if you have made the commit, make an --amend to rename your commit and retry it.
git commit --amend -m "PREFIX-000 Write your commit here"
try the push again.
If you are using BitBucket, this issue occured when I tried to push to a branch but that branch has writing disabled via the repository settings.
if you have already created a project locally and you want to upload it to git,
you will then need to do:
git status to see the changes you need to upload
git add . to add those changes to your repo
git commit -m "" to add a commit message
git push origin master
that way I solved the very same problem I
was having.
it might be a configuration issue
I fixed this issue after updating the global user.email value with my email
git config --global user.email my#email.com
Note: You need to delete the previous commit because it had the wrong email in the commit

How to check if my repository has been deployed to heroku?

I have several repositories and only one has been deployed to heroku. How do I find out which one? Because I made a change in one repo and tried to push it but got a warning fatal: 'heroku' does not appear to be a git repository. Is there a command?
It looks like you have not created heroku repository yet or you are in wrong directory. Go to the directory where you have your app then create heroku with the help of below commands.
git init
heroku create
after creating heroku you can add and commit heroku with the help of
git add .
git commit -am "any comment"
last step will be to push all your data to heroku server by
git heroku push master
If repository is already created, you can check associated repository by hitting below command
$ git remote -v
You may need to run heroku git:remote command to associate a Git repository with an existing application
for more information on how to deploy app click here

Resources