Using Git is wonderful. I often wonder why I use it and then I end up full of anxiety 🙂
Check out my post on how to initialise a new fresh repository on github, bind to local directory and push files to remote repository.
How it works
GitHub works on the principle of mirroring between local and remote repositories. Each code change actioned is made audible through a commit mechanism which provides the basis for granular tracking of changes made.
These changes can be pushed (sent) from the local machine to a remote repository, or pulled remotely to the local machine.
As a reminder before committing anything to Git, think about whether it contains sensitive information (e.g. passwords, PIN, credit card details, API keys, etc). If you have uploaded data of a sensitive nature that should not be available via GitHub, refer to my other blog post linked.
Creating a new repository
On Github create a new repository – take note of the settings presented on the Quick setup screen (specifically the URI e.g. email@example.com:<user><repository>.git)
# Initialise the local repository
Adds a .git directory into the current directory
(Adds directories for branches, hooks, info, objects, refs + three text files HEAD, description, and config)
# Add the current directory and subdirectories to git
This will create a new index file within your .git folder
# Add message to attach to commit (i.e. the files you wish to store on git)
git commit -m "First commit"
This comment will be attached to the first changes made which are to be pushed to your remote repository. The message can be amended to whatever you wish and should provide suitably informative information on what is being done.
# To bind the local directory to the remote repository we need to perform the following action
git remote add origin <remote repository URI>
Note the URI is actually provided on the initial GitHub quick setup screen when creating the repository.
# Push the files to the remote repository
git push origin master
This pushes the associated files/directories to the remote repository.
# If you want to know which remote repository is being pointed to
git remote -v
This will verify the source for fetch and push based on the current configuration.
Note: until you actually succeed in pushing the local files remotely, you can just remove the local .git folder to restart the process. Once the files are available remotely, you can easily check via the GitHub website.