GitHub Cheat Sheet

 

Inside the folder
you want files to be version controlled:

 

Git init

 

Having files created
and existing in the folder, you wan to ADD them to staging:

(either use period
to select all, or specific one file at a time with name)

 

Git add .

 

To see status of the
files added to staging or at any point:

 

Git status

 

To remove files
(all) added to the staging area:

 

Git rm –cached -r .

 

In order to commit
the files to the repository:

(-m means give it a
description for the checkin)

 

Git commit -m
“Create file 1”

 

In order to move
this local repo to online one:

 

Create a repository
on GitHub under your account

 

Create a reference
to the online repo within your local repo:

(the name after add
can be anything, origin is example, the URL is from the Github online repo)

 

Git remote add
origin https://github.com/dsitdev/Story.git

 

The master branch is the main branch that
exists in the local repo, we then push and sync the local master to the report
Github one.

 

Files in a git
initialized folder can be set to ignore.

 

Create hidden file

 

Touch .gitignore

 

Open .gitignore

 

Now add the names of
the files to the text document and save

 

If you did a
recursive ADD to all files, it would ignore them.

 

GithHub as a repo of Git Ignore premade files
for certain applications, you can create a gitignore in the xcode project and
copy and paste the gitignore code into it

 

To clone a GitHub
repo, find the link online for the Github repo, then in terminal, nav to the
folder you wan to drop files to and:

 

Git clone https://theurltotherepo.com

 

BRANCHING (creating
a side branch) off main allows you to use main branch code while working on
another shared effort, if the side branch dev creates a good result, we can
then MERGE the branch to the Main branch.

 

Create a new branch
with a name:

 

Git branch
experimental-features

 

View the branches
(master will have a asterisk):

 

Git branch

 

To switch focus onto
the new branch from the main (or another branch):

 

Git checkout
experimental-features

 

The files that exist
in the git folder will still be visible from command line, now they can be
opened and edited and saved.

 

The same ADD and
COMMIT commands will apply to the changed files in this new branch.

 

Git add .

 

Git Commit – m
“Change the fuel type to hydrogen”

 

View the changes
added under the new branch name:

 

Git log 

 

You can swap back
and forth between branches, the current branch your in will have a * near it:

 

Git branch

 

Git checkout master

 

 

MERGING the side
branch to the Master branch. From the Master branch (git checkout master),
merge the side branch:

 

Git merge
experimental-features

 

Merging will open a
VIM editor to allow you to edit the merge message, this can be closed by using:

 

:q!

 

This newly merged
master branch can be pushed back up to the Github online repo:

 

Git push origin
master -u

 

GITHUB repo creation

 

Create a new repo
from Github site.

 

If you leave the
‘Initialize the repository with a README’ then that will allow you to provide
the repo with a write up /wiki like landing page for the repo.

 

 

Create a new file

Pull request is now shown asking if you want to pull the changes to the side branch
into the master branch.

Now we create a new file, this time, for instance, a section on terminology related to the widget.

Committing this to the Master branch when done.

Back
to Insights, we can see the Master branch reflecting the creation point of the
original document, a light blue branch showing the edit to the document in its
own branch and finally the last point on the Master branch showing the addition
of the terminology document.

 

Now
we are ready for a merge. Click on Pull Request and view the branched change vs the master branch document. The additional content is shown in the green from the change made in the side branch.

 

The next screen will indicate if there are any conflicts. The green check shows that no conflicts are existing at this time.

 

When ‘Merge pull request’ is selected we have an opportunity to update this event with a betteescription that the one auto populated by the program before we select’Confirm merge’

After confirming the merge, a confirmation screen appears indicating that the pull
was merged and the request was closed.

 

Now the blue side branch can be seen as merging into the master branch.

 

Forking is a term where a remotely hosted (GitHub) source code is copied into the remote profile
of another user/account.

 

Any project can be forked and a copy will appear in the Github repository of the fork requestor.

 

They can continue to make changes to the Master branch or generate side branches as normal.

 

The interaction between the forked code and the original source code on Github under the other
account can ossure with Pull requests.

 

Pulling a request is where the original source repository owner from where the repo was forked from,
sees a request from another user to merge their changes with the original repo.
The original owner must approve and then ‘pull’ that request into their repo.