What is Github ?

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

Beyond 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.


Benefits of using Github :

Collaboration

If we ever plan on working on a project with at least one other person, Github will make our life easier! Whether we are building a hobby project with our friend or we're collaborating with the entire world, Github is essential

Open Source Projects

Today Github is THE home of open source projects on the Internet. Projects ranging from React to Swift are hosted on Github. If we plan on contributing to open source projects, we will need to get comfortable working with Github

Exposure

Your Github profile showcases your own projects and contributions to others' projects. It can act as a sort of resumé that many employers will consult in the hiring process. Additionally, you can gain some clout on the platform for creating or contributing to popular projects.


git clone

	
	$ git clone [url]
	

To clone a repo, simply run git clone . Git will retrieve all the files associated with the repository and will copy them to our local machine. In addition, Git initializes a new repository on our machine, giving us access to the full Git history of the cloned project.


Permissions

Anyone can clone a repository from Github, provided the repo is public. we do not need to be an owner or collaborator to clone the repo locally to our machine. We just need the URL from Github.


Configuring SSH Keys

we need to be authenticated on Github to do certain operations, like pushing up code from our local machine.

Our terminal will prompt us every single time for our Github email and password, unless, we generate and configure an SSH key! Onceconfigured, you can connect to Github without having to supply our username/password.

Follow this link Github docs for SSH Key Setup to create and setup SSH key from github.


Existing Repo

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


Start From Scratch

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


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 "destinations" as remotes.

Each remote is simply a URL where a hosted repository lives.

	
	$ git remote
	
	$ git remote -v
	

To view any existing remotes for our repository, we can run git remote .This just displays a list of remotes. If we haven't added any remotes yet, we won't see anything!


Adding A New Remote

	
	$ git remote add [name] [url]
	

name : It's just a name for a URL. Origin is a conventional Git remote name, but it is not at all special.

url : URL of Github Repo.

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


Other Remote Commands:

	
	$ git remote rename [old] [new]  =>  to rename a remote
	
	$ git remote remove [name]	=> to remove a remote
	

Master Branch to main Branch:

	
	$ git branch --move master main
	

There’s no master branch locally anymore, because it’s renamed to the main branch in Github. Rename your local master branch into main with the above command


Pushing

	
	$ git push [remote-name] [branch-name]
	
	$ git push origin main
	

To push up my main branch to my Github repo (assuming my remote is named origin)