Note: Before starting this, let’s assume initial setup of Git and GitHub is already done.
First create a directory on your local machine. Open a terminal (Mac) or GitBash (Windows) and change the directory to created directory. Here “Test” is the directory created on Desktop.
In order to be able to communicate with the Central Repository created in GitHub, Initializing the created directory as Local Repository would be required. Git init is a one-time command to use during the initial setup of a new repo.
Command : git init
Next clone the Central Repository from GitHub to Local using one of the methods “HTTPS” or “SSH”. Here method used is HTTPS. Copy the HTTP/S URL to clone it to local.
Use the git clone command with copied URL from GitHub. Once cloned the central repository to local , the repository would appear in the local directory. Here created repository in GitHub is “DevOpsDiggers”.
command : git clone <Copied URL from GitHub>
“git status” command also would help to validate the cloning process and it says on which branch user is on.
Command : git status
Change the directory to the cloned repository.
Created the new file in Local Repository with the name of “FirstFile” . Before adding the file if the status is checked, the file name would show-up in red color.
Add the file using the git add command and check the status. The file would be seen in green color.
Command : git add <filename>
Then commit the added file using git commit command along with commit message. This commit message would help others to understand what has been committed to the GitHub Central Repository.
Command : git commit -m “commit message”
Right after committing the file if checked for the status, file would not show up but displays the message “nothing to commit, working tree clean” and the branch is ahead by some commits. This means, the pushing of file to GitHub Central repository is yet to be done.
Final step is to push the file using the git push command.
command : git push
Pushing first file to GitHub repository is done and the file can be seen in GitHub repository.