How to Upload to Github Through Command Prompt

GitHub CLI is GitHub on the command line. Information technology brings pull requests, issues, and other GitHub concepts to the concluding side by side to where you are already working with git and your code. — GitHub

This tutorial is a short 10 minute read if you follow forth, and will completely guide yous on how to get started. We will look at how to install, authenticate, clone a repo, create a new repo, bank check condition, add together files, make new commits and finally, push your changes to GitHub. This tutorial will get you well on your way to using this new tool, please share it with whatever of your friends that are new to git in the command-line. Let'due south get started.

I have written a French version of this same article here → https://medium.com/@namusanga/comment-utiliser-github-cli-la-nouvelle-interface-de-ligne-de-commande-github-namu-ad4f75a70b51

Using -main instead of -master

Nosotros will start on a simple note, due to the recent controversies with black movements and #BlackLivesMatter there has been a general push for developers to move on from calling the principal branch in git -master to -master. Due to the relationship between the word 'master' in git and as it was used during slavery. Nosotros want to exist as inclusive as possible and volition adopt anything to make everyone experience equally comfortable as we can and button the community forward, we ❤ you all. That said, github has recently changed their documents to show the main branch every bit -principal and not -principal, this is true past default for all new repos every bit well, please take careful annotation of this. Quondam documentations that nonetheless use master will render an error if pasted without changing master to main or vice-versa if you're using an erstwhile repo.

The main branch will now be called chief, period. Mom said so.

Installation

Yes, GitHub CLI does crave git to be installed on your computer, therefore you will demand to install git before continuing. Information technology uses git internally for all functions that tin also be done by git like, cloning, pushing, merging etc.

Y'all tin download and install git from this link → https://git-scm.com/downloads.

Next, download GitHub CLI from here → https://github.com/cli/cli/releases/ and click next on every single dialog that pops up during installation. Piece of cake equally that we can move to authenticating GitHub CLI.

Brand certain to install the .msi for windows

Authentication

Afterwards installing GitHub CLI we demand to login and go it setup with our GitHub account. To do this you will need to have a GitHub account, if you don't, yous can brand one here → https://github.com/bring together it takes less than five minutes. Make certain y'all're signed into your github account in your browser.

Then open Command Prompt from the start menu and run.

          gh auth login        

This will cause GitHub CLI to start asking you for details about your business relationship.

Choose what type of github account yous have

Usually you will have a GitHub.com account, merely if you company has on-sight servers for storing GitHub project, and so you need to choose GitHub Enterprise Server, press enter.

Next you demand to login, select login with browser, this allows your browser to automatically cosign y'all into your business relationship, press enter.

Side by side select the onetime code given to y'all and paste it in the new tab that opens in your browser, and press enter.

And boom! merely like that, github is request you to verify you want this CLI to access your account, too easy! Click qualify and enter your countersign on the next screen.

Woohoo!!!!

If you head back to command prompt, gh, is asking you to choose a protocol, let'due south go with HTTPS for simplicity.

Hahahaha — All done!

Enjoying this article and so far? Come hang out with me on Twitter, I evaluate new technologies on a regular to see if they will be helpful and relieve time for your projects 😊.

Cloning Existing Repo

With this new CLI it's even easier to clone a repo, we will use this one for this example → https://github.com/namusanga/How-To-Use-GitHub-CLI-Windows . Run:

          gh repo clone https://github.com/namusanga/How-To-Use-GitHub-CLI-Windows        

Every bit y'all can meet, gh gracefully cones the repo and creates its folder in my directory. At present run cd followed past the proper name of the repo to enter its binder.

          cd How-To-Use-GitHub-CLI-Windows        

Running dir tells the control line to listing all files in the directory.

Only like that, we have cloned a remote repo, adjacent nosotros need to learn to create a local repo from scratch.

Creating A New Repo

Close the previous command line and open a new ane, let's create a new repo using gh. One of the coolest features of github CLI is that when you create a repo on your machine information technology automatically gets created on you github business relationship every bit well. Run

          gh repo create [name]        

Replace [proper name] with any random name for your repo. You will need to reply some interactive questions about whether the repo is public or private and whether or not it should be cloned on your machine.

My results while creating a public repo

For the remainder of this tutorial, you need to be in the repo you have simply created. Open a terminal in that location using the following instructions.

Opening A Terminal In A Location

As a git user, you lot demand to know how to open a terminal in the location of a git project, it's super easy though.

  1. Open up the location in your file explorer.
  2. Copy the path to the location from the tiptop bar.
  3. Open a terminal and blazon cd [path] replace the [path] with the content on your clipboard by but correct clicking in anywhere in the terminal. For terminals correct-click unremarkably means copy/paste.

Once you're washed opening a git directory on your final, y'all're ready to start working on it.

Checking Status

Checking the condition of a repo in gh remains the aforementioned equally for git since gh doesn't offer an extra check condition role. In this department we shall merely look at the check status office for completeness. (bet yous didn't know that was a discussion 😂😂😂)

Anyway, checking status allows one to know which changes take been made to a project, new files, modifications, etc you can do this to know if you have anything to commit.

→ Create a new file in your repo called 'testing-condition.txt'.

→ Then head to the command line and type git condition

This is what I get

Notice how it says → Untracked files. This means these are the files that need to be added to git. To add together them run git add * This add all new files in your repo. If yous run status now, the file is greenish, this means it has been staged 'aka it is ready to exist committed'

Before we do that though, permit's make a change to information technology. Open the file and type annihilation, and I mean anything!

There we go

If you check git status again at present, at that place are two things that demand committing.

  1. This file was created and
  2. It has been edited.

Now that we know what the status of our project is, it'southward time to commit.

Run git commit -a -m "just added a random file to test git status" this command volition tell git to save these changes.

At present that were washed learning some git basics, it's time to push our changes to the cloud.

Over again gh doesn't provide a part for this, simply information technology does simplify the procedure, so but run git button

And just like that, we're washed!

hodgettsarfeaught.blogspot.com

Source: https://medium.com/swlh/how-to-use-github-cli-the-new-github-command-line-interface-2016b84f29c0

0 Response to "How to Upload to Github Through Command Prompt"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel