Git: creating a GitHub repo (https://github.com/user/…) from the command line

This took me forever to work out. I took a while ploughing the git and github manuals, thinking that the answer was there, but I think not. To be clear then, and possibly not, as I thought the manuals were answering this question but nothing I tried worked:

I am on a local client. Without going to the GitHub UI, I want to create a GitHub repository from the command line on my local client. 

Firstly, I finally got with the program and got onto Bash for Git. It’s only unix commands of course, so I just need to remind myself of that world.

Having started a bash shell anyway, and without the need to go into a cloned, local repo, I can run this from anywhere, which creates an empty repository with the requested name (“CB3”, in this case):

 curl -u 'user:password' https://github.com/user/repos -d '{"name":"CB3"}'

 

Credentials

Now I found I had to do this (replace [user:password] with [jane:secretphrase]) :

 curl -u 'user:password' https://github.com/user/repos -d '{"name":"CB3"}'

, when what I wanted to do was this, which should be OK, but just resulted in the command line hanging:

 curl -u 'user' https://github.com/user/repos -d '{"name":"CB3"}'

 

Advertisements

Git: some common actions

This does not include how to create an account on GitHub, and does not include how to install Git on your client. The local client examples are on a Windows 10 platform.

Create a repository on Github:

I prefer to use Git from a PowerShell session (rather than e.g. a Git for Bash session). The installation of Git will likely have added it to the path. See above.

From there I ran the command in the lime/pink box above (“git clone… “). That warned me as you see that I was cloning an empty repo. True.

I then followed the commands in the example above (git init, git add…, git commit…, git remote add., git push…).

Going back to the GitHub website showed me the README.md was now there.

Next, I added a new, empty file in the root of ExampleRepository:

New-Item -Path ./testfile.txt -ItemType File

To make git aware of this and any other files in the repo, I ran (note the dot):

git add .

No feedback on the command line, but when I commit…

 

Now push the committed file or files up to the remote server:

To bring back down anything that might have changed on the remote server:

If things change locally, and that needs committing and pushing…

(May 2018)
I have a 32-bit tablet… and Github Desktop just doesn’t run on there. So I had a reason to use the command line git.

I had an existing repository, to which I wanted to add folders and files. So in summary, the actions were:

  • clone the repo to a local folder [git clone [https:// etc (get it from github.com/user)
  • add the files and folder [git add [example folder root]]
  • commit that new stuff and any changes [git commit *]
  • note this opens notepad – put a comment, save and exit
  • push the files up to github [git push]

And it was honestly that simple

 

Git: move or rename a file or folder

as


If you want to change the case of a file or folder, but not rename it, then you need to do this in 2 steps. E.g. given a folder [Test], that I want to change to [test], then do this:

git mv Test temp

git mv temp test

Github Desktop, for example, will interpret that as a single rename (Test -> test), and you can commit without further ado. I could not find a single step way to do this rename.

 

Github: file overlay icons

Summary: while apparently not a core part of Git/Github, the combination of Git Extensions and TortoiseGit does the job

Use case: within Windows/File Explorer, I want to see the status of my files relative to the Git repo, e.g. Added, Changed, Deleted, Unchanged

I googled…[file overlay icons github]

https://github.com/owncloud/client/wiki/Overlay-Icons ->

https://github.com/owncloud/client/issues/1818

I am very used to explorer icons in other source control systems, e.g. svn/Tortoise, and have taken them for granted. However, there seems to be a lot of huffing and puffing around the subject on the Git forums, with the opposite camps of “What on Earth do you want that for?” and “it is mad this is not available by default”.

This Stackoverflow post talks about [“GitExtensions is awesome for the true git experience. TortoiseGit obscures Git, forcing it into a “simple” experience. TortoiseGit has icon overlays though. The two work quite nicely together, so just install them both, use them for their strengths, and ignore them for their weaknesses.”]

Looking for one takes us here [https://github.com/gitextensions/gitextensions], here [https://github.com/gitextensions/gitextensions/releases/tag/v2.50.01]

and the other here [tortoisegit] and [https://tortoisegit.org/]

You will see from the last screenshot that it works well enough, imo.

 

 

 

GitHub: searching in your own repositories

While not immediately apparent to me, GitHub does have pretty good search. The root URL is, amazingly:

https://github.com/search

Also here in a new tab.

One example is enough, as the GitHub URL gives more detail. Note the syntax used is:

[search string](space)[literal "user:"][repo owner to search]

, as in:

Also note that you don’t seem able to enter wildcards…

Pretty much confirmed by this: