-Kipling
Here is the scenario: you have a GitHub account and you also have some work in a folder on your Windows PC you would like to place in an online repository. Furthermore, you do not have the git command line tools available (such as git bash) and, what is more, you don't particularly want to mess with all that sort of thing. You do have the GitHub Desktop GUI tool though.
Ultimately, all you really want to do is just place the local folder under some sort of git version control and then move it up to GitHub and automatically create a repository for it there.
Warning, you should always make a backup copy of your files before messing about with GitHub Desktop. It is not likely anything will go wrong in a way that affects your work - but why take chances.
This operation is simple if your repository on GitHub is to have the same name as the local folder on the PC. In that case you just create a new local repository in GitHub Desktop and then push it up to GitHub. The main thing to be aware of is that when GitHub Desktop creates or adds a new local repository it always wants the folder name to be the same as the name of the repository. So, if your directory structure looks like …
TopLevelDirectory | - File1 not for GitHub or version control | - File2 not for GitHub or version control | - ProjectName | - FileA for GitHub and version control | - FileB for GitHub and version control | - FileC for GitHub and version control… all you need to do is choose the Create New Repository option in GitHub Desktop, choose the
TopLevelDirectory
as a target and give it the name ProjectName as the name of the local repository.
Since the ProjectName
folder already exists, GitHub Desktop will not create it and will create the appropriate
git tracking files and subdirectories in the existing directory. You will end up with a structure like …
TopLevelDirectory | - File1 not for GitHub or version control | - File2 not for GitHub or version control | - ProjectName | - FileA for GitHub and version control | - FileB for GitHub and version control | - FileC for GitHub and version control | - .gitattributes | - README.md | - .git | - … more filesIf you make a mistake and specify the
ProjectName
folder as the target when you create the new local repository, you will
end up with a structure which looks like …
TopLevelDirectory | - File1 not for GitHub or version control | - File2 not for GitHub or version control | - ProjectName | - FileA for GitHub and version control | - FileB for GitHub and version control | - FileC for GitHub and version control | - ProjectName | - .gitattributes | - README.md | - .git | - … more files… and that is not what you want. In this case just delete the bottom
ProjectName
directory and its contents
and also delete the local repository in GitHub Desktop (or see below for how to fix it). Once you have done that, try again.
If you are satisfied that you have created the local repository in the way you wish, make it the active repository and press the Publish this Repository to GitHub button located on the top right hand side of the GitHub Desktop to send the repository up to GitHub.
What about a situation in which the name of the local folder on the PC is not the same as the name of the Repository name you wish to use on GitHub? This often happens for me as I tend to set up project directory structures which look like ...
ProjectName | - File1 not for GitHub or version control | - File2 not for GitHub or version control | - FolderWithGitHubDetails | - FileA for GitHub and version control | - FileB for GitHub and version control | - FileC for GitHub and version controlWhat I want is all of the contents of the
FolderWithGitHubDetails
to be a local git repository named
ProjectName on the PC and then be able to move it up to GitHub and create a repository there also
named ProjectName. In other words, I wish to be able to create a git repository via GitHub Desktop GUI in
which the name of the repository is not the same as the name of the local PC folder. This is not a simple
one-step operation with GitHub Desktop - but it is quite do-able.
Here is how it is done.
FolderWithGitHubDetails
as the target.
ProjectName
below the FolderWithGitHubDetails
folder. GitHub Desktop always does
this - there does not seem to be a way to stop it.
ProjectName | - File1 not for GitHub or version control | - File2 not for GitHub or version control | - FolderWithGitHubDetails | - FileA for GitHub and version control | - FileB for GitHub and version control | - FileC for GitHub and version control | - ProjectName | - .gitattributes | - README.md | - .git | - … more files
ProjectName
folder into the FolderWithGitHubDetails
folder above and
delete the newly created ProjectName
folder at the bottom of the tree. If you do not see the .git
sub-folder. Use the Show Hidden Files check box option under the Windows Explorers View menu to make sure it is visible. You must copy the contents of the .git
subfolder as well. Once that is done,
the directory structure should then look like this ...
ProjectName | - File1 not for GitHub or version control | - File2 not for GitHub or version control | - FolderWithGitHubDetails | - .gitattributes | - README.md | - .git | - … more files | - FileA for GitHub and version control | - FileB for GitHub and version control | - FileC for GitHub and version control
FolderWithGitHubDetails
folder as an existing local repository in GitHub Desktop. This is now
possible since it now contains all of the necessary git tracking files and subdirectories.
FolderWithGitHubDetails
and
any files you place in it will be under version control and can be commited and pushed as normal using the GitHub Desktop GUI.
The contents of this web page are provided "as is" without any warranty of any kind and without any claim to accuracy. Please be aware that the information provided may be out-of-date, incomplete, erroneous or simply unsuitable for your purposes. Any use you make of the information is entirely at your discretion and any consequences of that use are entirely your responsibility. All source code is provided under the terms of the MIT License.