First go to the working directory which you would like to sync with GitHub, initalize the local directory as a Git repository:
git init
then add the fields in your new local repository by
git add .
Commit the files that you have staged in your local repository:
git commmit -m "First commit"
Next, add
git branch -M main
add the URL for the remote repository where your local repostory will be pushed:
git remote add origin <remote repository URL>
The step of pushing files (changes) in your local reposityr to GitHub by:
git push -u origin main
or
git push origin master
If they does not work, we can use:
git push origin main --force
or
git push origin master --force
Remove .DS_Store files
To remove .DS_Store fiels from a Git repository, you can first remove exisiting fields from the repository:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
then do
echo .DS_Store >> .gitignore
More details see this link.
git add .
Then do commit:
git commit -m "updated"
Check if the repo is connected to the directory:
git remote -v
Then do the push:
git push origin main --force
Note that since August 13 2021 you need to use a personal access token instead of passowrd authentication.
You can follow this link, or github account, Settings --> Developer setting --> Personal access tokens -- > Select "repo" and "delete repo" --> Generate new token
Use your email address and token as password to access to github.
Add in your MacOS, you can do (see more details here):
- go to KeyChain Access,
- Search for "GitHub",
- then when then result "github.com" pops up, change the account or password to your new account, and save.