Starting with Github - Create a new repository on the command line
This is specifically for Github.com. I have set up an SSH key and authenticated it, and now I want to start building repos. There is other ways to do this, but i'd rather do it locally on the command line.
$ mkdir test # make a new directory in your main git folder $ cd test # change to that directory $ gh repo create test --public # create the repository folder on github $ echo "# test repository" >> README.md # make a line in a file called README.md that says # test repository $ git init # initialize the repository $ git add . # or -A for all or README.md for one file $ git commit -m "test commit" # commit with the message test commit $ git branch -M main # specify the branch is main $ git remote add origin git@github.com:oddlej/test.git # this is showing how you are going to authenticate. It can be ssh as I have setup up or https $ git push -u origin main # push these changes to the server
That's it. You now have a synced version on Github.com. If you get any errors, you either have a directory under that name, or have configuration problems. If you have trouble on the push after the set remote line check here. Once the remote is set you need to use set-url to change it. Also here is a few links to using the add command. Here is the complete sequence on my machine, and here's a link to it.
stakes@kelethin:~/Desktop/mygit$ ls as c html music README.md stakes@kelethin:~/Desktop/mygit$ mkdir test stakes@kelethin:~/Desktop/mygit$ cd test stakes@kelethin:~/Desktop/mygit/test$ gh repo create test --public ✓ Created repository oddlej/test on GitHub https://github.com/oddlej/test stakes@kelethin:~/Desktop/mygit/test$ echo "# test repository" >> README.md stakes@kelethin:~/Desktop/mygit/test$ git init Initialized empty Git repository in /home/khadas/Desktop/mygit/test/.git/ stakes@kelethin:~/Desktop/mygit/test$ git add . stakes@kelethin:~/Desktop/mygit/test$ git commit -m "test commit" [main (root-commit) 0027e18] test commit 1 file changed, 1 insertion(+) create mode 100644 README.md stakes@kelethin:~/Desktop/mygit/test$ git branch -M main stakes@kelethin:~/Desktop/mygit/test$ git remote add origin git@github.com:oddlej/test.git stakes@kelethin:~/Desktop/mygit/test$ git push -u origin main Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 221 bytes | 221.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:oddlej/test.git * [new branch] main -> main branch 'main' set up to track 'origin/main'.
I then changed the README.md file on the Github app on my phone to test and committed it. Let's get it locally with a pull.
stakes@kelethin:~/Desktop/mygit/test$ git pull remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. Unpacking objects: 100% (3/3), 904 bytes | 904.00 KiB/s, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) From github.com:oddlej/test 0027e18..123823d main -> origin/main Updating 0027e18..123823d Fast-forward README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) stakes@kelethin:~/Desktop/mygit/test$
Once you have completed this sequence, you will use some of these commands to commit new changes to the folder. This is a great starting point as well. You can use master instead of main, I just like my main branch being called main. Git 'er done! :p
Proudly powered by an IDE, a Text Editor, and some Internet Searches.
2024 dispelled.ca end of file.