Pushing new files in a new repository Git

扶醉桌前 提交于 2019-12-11 02:57:51

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/12144512/pushing-new-files-in-a-new-repository-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!