Says you have been working on some code for a while, and are ready to move it to Github. Here is what Github tells you how to do after you create a repository there:
Note: I suggest choosing SSH, so you don't need to log in every time. To set this up, please follow the official doc here
echo "# dnx-tallentAPI" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:deniapps/dnx-tallentAPI.git
git push -u origin main
Here are a few issues:
git init
, it will not specify the Git user, so the global Git user will be used. If you have only one Git account, then it's fine, but if you have multiple users, then you may see your Github repo shows a different username that you don't want. So make sure to add the user to the git config file first.Okay, so here is the correct way:
// First "cd" to your project root
git init
vim .git/config
Add sshCommand
under [core], which tell Git which account you are going to use. You don't need this if you have only one account. To set up SSH with Github, check the official doc here. And then, add [user] info, after that it will be like this:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
sshCommand = ssh -i ~/.ssh/id_rsa_adam
[user]
name = Adam C.
email = adam@deniapps.com
The next step is adding all files you would like to commit to the repo. Remember to have a correct .gitignore file created before running git add .
git add . ### WARNING! - CHECK YOUR .gitignore to make excludes the files you don't want to coimmit
git commit -m "first commit"
git branch -M main
Again, Instead of git remote add origin https://github.com/deniapps/dnx-tallentAPI.git
, I suggest using SSH, like below, so you don't need to log in every time. To set this up, please follow the official doc here.
git remote add origin git@github.com:deniapps/dnx-talentAPI.git
git push -u origin main
Updated: Apr 22nd, 2022
Try to clarify some confusion at least I had.
git clone git@github.com:deniapps/private.git --config core.sshCommand="ssh -i ~/.ssh/id_ed25519_adam"
(Note that you should provide the private key here.)git config user.name “USERNAME”
’ & ‘git config user.email “USEREMAIL”’
.