windowsgitgithubgit-bashgit-push

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.


Solution

  • 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