Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 605
Jeewantha Lahiru Avatar asked Jan 24 '26 07:01

Jeewantha Lahiru


2 Answers

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
like image 72
Pankaj Saini Avatar answered Jan 25 '26 19:01

Pankaj Saini


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.

  1. Git clone from the git repository you need to push to. Just make sure you create a new directory for the cloned code.
  2. Copy the contents of the cloned repository into the local directory that has your current code. Make sure to copy the .git (hidden) file.
  3. cd into your local directory and run git remote -v. You should see the remote repository git address.
  4. git add -A to add whatever change you require and commit it.
  5. Finally git push
like image 28
Jonathan Avatar answered Jan 25 '26 21:01

Jonathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!