How to add a project to Gibhub¶
Preparation:¶
- Check git is installed on your machine:
git --version
- Download the latest git:
git clone https://github.com/git/git
Create a new repository(repo) in GitHub¶
- Click
+ New Repository
on the right hand corner on the menu bar - Name the new repo
- Don't initialize with
README.md
or.gitignore
yet to avoid conflicts at this time - Copy the new repo's URL on clipboard
Create repo in local directory¶
- Open terminal
cd
into the project directory- Initialize local repo:
git init
- Stage all changes in current directory,
i.e., all files in the curent directory to the repo:
git add --all
- Commit all stages files
Linking the local repo with the remote repo¶
- Add the remote repo to the local repo, and alias it as 'origin':
git remote add origin copy-new-repo-URL
- Verify the remote repo:
git remote -v
- Push commits to github repo:
git push origin master(or branch name)
Troubleshoot error message: 'git@github.com: Permission denied (publickey)'.¶
- Check for existing ssh key: https://help.github.com/en/github/authenticating-to-github/error-permission-denied-publickey
- Generate a new ssh key: https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
- Add the ssh key to Github account: https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-accountå
Reference:
- Adding an existing project to GitHub using the command line: https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line