Pushing new files in a new repository Git

2019-07-16 12:47发布

I'm new to git and haven't gotten the idea of the workflow fully. So I've created a repository on the github.com and have been able to push all the files from my computer. Now I've created a new repo on the github and created a new folder on my computer. Everything gets pushed from the new folder, but it gets pushed in the old repository, as opposed to the new one. How do I switch to the new repository? Thank you for your help in advance.

2条回答
贼婆χ
2楼-- · 2019-07-16 13:19

You can use git remote to view and edit the upstream repositories your local repo is connectted to. To view current remote repos

>> git remote -v
"remote-alias" ssh://url.of.remote.repository/ (fetch)
"remote-alias" ssh://url.of.remote.repository/ (push)

Each repo has a fetch and a push address that are used to fetch from the repo and push to the repo respectively. These are separate to allow setups where the fetch happens over http but the push happens over ssh for instance.

Use git remote rm alias to remove an old remote repository and

git remote add "alias" http://url.to.new.remote

to add a new one (just replace "alias" with the actual alias you want to use).

When you do a git clone a new remote is added by default under the alias origin, this is just a convention and you can name the aliases what ever you wish.

You can have more then one remote repository and when you push just define which one you want to push to

git push origin /src/java
git push dev-tests /some/other/path
查看更多
祖国的老花朵
3楼-- · 2019-07-16 13:37

To push from a different repo, you need to move to the path of that new project and type again:

git init

*for each new project you need to type 'Git init' again

Also, add the new repo of github as remote in the new project since the path of the new project

git remote add origin git@github:<Github user>/<project name>.git

*Replace with the appropiate

查看更多
登录 后发表回答