Easy way if poss: its easiest if possible to just create the project on github first (remember to tick the checkbox to create a readme.md file ).
In the options you can even select a relevant gitignore file so it will ignore relevant stuff based on your stack ( eg spring boot, wordpress or whatever )
Then (locally) git clone the new repo url e.g.
git clone [SSH url] ( git WEB URL is switched off , use a SSH key for security now )
careful with this step (backup first): remember to delete local git ref (if and only if you’ve been using git locally only on the project – rm -f <repo_folder>/.git)
useful cmd on local:
#show config
git config –list
# show remote/s
git remote -v
# pushing to a remote ‘git push [REMOTE NAME] [REMOTE BRANCH]’
git push origin main
Be care using commands on this page ( they are intended for a new empty remote repo, they can delete a remote repo ). Make sure you have anything you dont want to lose backed up.
I’m using local git client (below), on Mac.
git version 2.33.0
In project dir (after git init )
If local branch is called master:
// rename to main
git branch -m master main
EndIf
Create repo on GitHub.com ( in web browser – IMPORTANT ) e.g. create repo called: some-repo [ don’t know why doesn’t seem to work creating the new remote repo from the local cmd line].
git remote add origin git@github.com:[GIT USERNAME]/some-repo.git
git remote -v
// if ‘fatal: refusing to merge unrelated histories’ add the switch below to pull
git pull origin main –allow-unrelated-histories
git push -f origin main
for later pulls from remote to local (ie to get the latest version):
git pull origin main
General git notes ( I’ll make this a reference section later)
Working in a team, a simple way. To pull / push merge conflicts and update remote (from: https://stackoverflow.com/questions/35025587/git-pull-and-resolve-conflicts )
One (simple*) way to handle this without branching or stashing:
-
stage/commit your changes locally
-
pull remote
-
at this point you’ll be notified of any merge conflicts. If git cannot automatically resolve merge conflicts, it will open the two versions in whatever editor you have set up as your default merge editor. I recommend BeyondCompare.
-
commit your merge, push your merge and commits remote master