Kenshō - Creating a New Repository on GitHub

To create a new project repository

tanya@tanya-jain:~$ mkdir The\ Stellar\ Adventurer/ # Makes a new directory/folder
tanya@tanya-jain:~$ cd The\ Stellar\ Adventurer/

Note: Backslashes are used in files or directories to specify the presence of more than one word.

Syntax: Word1-file\ Word2-file\ Word3-file.ext/

tanya@tanya-jain:~/The Stellar Adventurer$ git init

git init initialises an empty .git repository in the local system (or personal computer) with all the necessary .git files to perform operations in GitHub

tanya@tanya-jain:~/The Stellar Adventurer$ ls -la
total 12
drwxrwxr-x 3 tanya tanya 4096 Jul 5 23:33 .
drwxr-xr-x 43 tanya tanya 4096 Jul 5 23:32 ..
drwxrwxr-x 7 tanya tanya 4096 Jul 5 23:34 .git

The ls -la is used to list all the files and directories. The -la attribute shows the hidden files and directories.

tanya@tanya-jain:~/The Stellar Adventurer$ gedit ReadMe.md

.md extension is used for Markdown files. It is a good idea to start with a ReadMe.md file as it contains the description about the project and is usually the first file to be added or committed. It can be either a text (*.txt) or a Markdown (*.md) file.

For creating new repository from existing projects

It is advisable to add .gitignore file as well to mention in prior to git which files you do not wish to track at all in GitHub. This can be done using git add .gitignore

tanya@tanya-jain:~/The Stellar Adventurer$ git status
On branch master

Initial commit

Untracked files:
(use "git add ..." to include in what will be committed)

ReadMe.md

nothing added to commit but untracked files present (use "git add" to track)

git status is used to check the status of the staged area and tracked files.

Staged area
An area where the files are set as tracked and are ready to be committed and pushed to the local branch.
Untracked files
Files which are recently changed on the remote system and are not yet staged to be then committed and pushed.

git add is used for adding the changes to the stage area for changes. Similarly, git rm is used for deletion of previously existing files or directories in the local repository.

tanya@tanya-jain:~/The Stellar Adventurer$ git add *
tanya@tanya-jain:~/The Stellar Adventurer$ git status
On branch master

Initial commit

Changes to be committed:
(use "git rm --cached ..." to unstage)

new file: ReadMe.md

git commit is used to commit changes tracked on being staged. They are accompanied by the attribute -m followed by double quotes to add a message regarding the changes made.

tanya@tanya-jain:~/The Stellar Adventurer$ git commit -m "Initialising repository"

git remote add [branchname] [https://github.com/user/new_rep.git] adds a new branch of the name specified with a URL specified from which the changes in the local system will be pulled [fecth] and pushed to [push] the local repository. The status can be checked using the --verbose or -v attribute.

Linking or connecting the new repository on remote system to the local repository on GitHub

On the top right corner, under + dropdown, select New Repository Fill in the required details. It is advisable to not initiate the repository with ReadMe.md and create it yourself. Otherwise, this would lead to conflicts while pushing changes.

To solve this issue: Commit all the necessary changes using git commit so that the next command will not lead to loss of the changes currently made. Then, use the git pull command to fetch the changes from the local repository. This can be done by:

tanya@tanya-jain:~/The Stellar Adventurer$ git pull https://github.com/Tanya-Jain/The-Stellar-Adventurer.git

Continuing the setup on git

tanya@tanya-jain:~/The Stellar Adventurer$ git remote add origin https://github.com/Tanya-Jain/The-Stellar-Adventurer.git
tanya@tanya-jain:~/The Stellar Adventurer$ git remote -v
origin https://github.com/Tanya-Jain/The-Stellar-Adventurer.git (fetch)
origin https://github.com/Tanya-Jain/The-Stellar-Adventurer.git (push)

git push [from-branch] [to-branch] is used to push changes committed in git from the [from-branch] to the [to-branch]

tanya@tanya-jain:~/The Stellar Adventurer$ git push -u origin master

A possible mistake

Do not use SSH instead of URL to add a remote branch, or there will be authentication issues. SSH is beneficial to get the work done faster by not needing to enter the password multiple times. Though initially, URL must be used to set up the new repository adequately.

tanya@tanya-jain:~/The Stellar Adventurer$ git remote add origin git@github.com:Tanya-Jain/The-Stellar-Adventurer.git
tanya@tanya-jain:~/The Stellar Adventurer$ git push -u origin master
tanya@tanya-jain:~/The Stellar Adventurer$ git remote -v
origin git@github.com:Tanya-Jain/The-Stellar-Adventurer.git (fetch)
origin git@github.com:Tanya-Jain/The-Stellar-Adventurer.git (push)

The correction can be done by the following commands:

tanya@tanya-jain:~/The Stellar Adventurer$ git remote remove origin # removes the origin branch
tanya@tanya-jain:~/The Stellar Adventurer$ git remote add origin https://github.com/Tanya-Jain/The-Stellar-Adventurer.git
tanya@tanya-jain:~/The Stellar Adventurer$ git push -u origin master