Home > Software engineering >  Pushing and Committing an existing IntelliJ Project to a github
Pushing and Committing an existing IntelliJ Project to a github

Time:01-14

Disclaimer: I am very new to computer science and don't really understand all the lingo with Git/Github.

I have a project I created for a university class, and it was committed and pushed to a github account that was created by the course administrators - essentially, everything was mostly set up for me, and I don't really understand how github works. Now I am done the course and have made a personal github account and I want to commit and push my code to a new repo in my personal account. How do I do this?

In VCS -> Github I already removed my school account and added my personal account, but when I try to commit any changes, it tries to commit it to my school account still.

CodePudding user response:

You have to check the remote branch you are pushing to.

You can use:

git remote -v

With this command you will see where you are directing your code.

To change that destination you can use:

git remote set-url origin [insert your repo URL]

CodePudding user response:

TL;DR you'll have to create a new repository on GitHub, add the remote of that repository to your IntelliJ project1 (and remove the remote of the school repo), and then push to your own repo.

Assuming you already have created a new repository on GitHub, you can do the following:

  1. Copy the url from your git repo. (Use the copy button in step 3 from this GitHub guide).

  2. In IntelliJ, go to Git > Manage Remotes...

  3. Remove any existing remotes there.

  4. Click the plus to add your own repo, this is where you use the URL from step 1.

  5. Push your changes, they should be automatically pushed to the new repo (commit them if you haven't yet).

If IntelliJ is trying to push from your school account still, you'll have to update your username and email in the git configurations. Following the good ol' GitHub guide for changing username and changing email address:

Open the ternimal in a directory within your current git project (hit Alt F12 in IntelliJ):

git config user.name "Mona Lisa"
git config user.email "[email protected]"

Note that it is important that you use the email that is tied to your GitHub account here. The username you enter here will be displayed with all your commits in GitHub, it can be different from your GitHub user name.

To edit these settings for all your git repos, add the --global flag:

git config --global user.name "Mona Lisa"
git config --global user.email "[email protected]"

1 Actually you're adding the remote to the local git repo, via IntelliJ.

  •  Tags:  
  • Related