Add Existing Codes to New GIT Repo
Add Existing Codes to New GIT Repo
Ref: https://stackoverflow.com/questions/4658606/import-existing-source-code-to-github
Background
- Local sources codes exist, want to add / push them to a new remote ((bitbucket/github) GIT repository (without cloning-then-copying-overwriting)
Steps
-
Create the remote repository, and get the URL such as
git@github.com:/youruser/somename.git
orhttps://github.com/youruser/somename.git
If your local GIT repo is already set up, skips steps 2 and 3
-
At the root directory of your local source codes
git init
-
If you initialize the repo with a .gitignore and a README.md you should do
git pull {url from step 1}
to ensure ignore
-
-
Add and commit the initial repo
git add .
git commit -m 'Add codes'
-
Attach your remote repo with the name ‘origin’
git remote add origin {url from step 1}
-
Execute
git pull origin master
to pull the remote branch so that they are in sync. -
Push up
# push all branches git push # push master branch git push origin master # switch branch and push git checkout -b wy git push --set-upstream origin wy git push origin wy