Github Basics

logo-github

What is Github ?

Github is a hosting platform for git repositories. You can put your own git repos on Github and access them from anywhere and share them with people around the world . 

Beyound hosting repos, Github also provides additional collaboration features that are not native to git (but are super useful). Basically, 
Github helps people share and collaborate on repos

GIT VS GITHUB

  • Git : Git's version control software that run locally on your machine. You don't need to register for an account. You don't need the internet to use it . You can use Git without ever touching github

  • Github : Github is a service that host Git repositories in the cloud and makes it easier to collaborate with other people. You do need to sign up account to use Github.It's an onlien place to share work that is done using Git .

GITHUB is not your only option ...

There are tons of competing tools that provide similar hosting and collaboration features, including Gitlab , Gitbucket , and Gerrit .

Github's free

Why you should use Github ?

Collaboration

Open source projects

Exposure

Stay Up to Date

Cloning

So far, we've created our own git Repositories from sratch , but often we want to get a local copy of an existing repository instead .

To do this , we can clone a remote repository hosted on Githunn or similar website . All we need is a URL that we cann tell Git to clone for use .

git clone

To clone a repo , simply run git clone <url> .

Git will retrieve all the files asssociated with the repository and will copy them to your local machine.

In addition , Git initalize a new repository on your machine, giving you access to the git history of the cloned project .

Permissions

We are not limmited to github repos

SSH Key

How do i get my code on github ?

options 1 :

If you already have an existing repo locally that you want to get on Github...

  • Create a new repo on github

  • connect your local repo (Add a remote)

  • push up your changes to github

options 2 :

Start from scratch

If you haven't begun work on your local repo, you can ...

  • create a branch new repo on github

  • clone it down to your machine

  • do some work locally

  • push up your changes to github

Pushing code

To get your own changes and git history up on github,we need to push them up. the typical workflow looke something like this :

  • make some chanes locally

  • add and commit those changes

  • repeat

  • push new commits to github

Remote

Before we can push anything up to github, we need to tell git about our remote repository on github. We need to setup a 'destination' to push up to.

In Git,We refer to these 'destination' as remotes Each remote is simply a url where a hosted repost lives

Viewing remotes

To view any existing remotes for your repository, we can reun git remote or gi remote -v (verbose,for more info)

This just displays the a list remote . If you haven't added any remotes yet , you won't see anything !

Adding a new remite

A remote is really two things : a URL and label . to add a new remote,we need to provide both to git

Example adding a new remote

anytime i use the name "origin".I'm referring to this particular github repo url

what is Origin ?

origin is a conventional git remote name,but it is not at all special. It's just a name for a URL.

When we clone a Github repo, the default remote name setup for us is called origin . You can change it . Most people leave it .

Rename origin

They are bit commonly used,but there are commands to rename add delete remotes if needed ,

Pushing

Now that we have a remote set up, let's push some work up to Github! To do this , we need to use the git push command .

We need to specify the remote we want to push to and the secific local branch we want to push to that remote

Pushing in detail

While we often want to push a local branch up to a remote branch of the same name , we don't have to ~

the -u option :

The -u option allows us to set the upstream sets the upstream of the local master branhc so that it tracks the master branch on the origin repo

this mean

overview environment github

Last updated