Create and manage Github repository from your terminal

Create and manage Github repository from your terminal

A step-by-step guide to setting up a new Git repository on your local machine and managing it entirely from your terminal

I prefer to work in the terminal and use my keyboard. I always try not to exit my editor once I start coding, and I avoid using my mouse during that time. I think you feel the same way, so let's commit to staying in the editor from the beginning of the project.

Steps

1. Install Github CLI to your machine

Download and install the GitHub CLI from https://cli.github.com. For the official installation instructions and source files, you can visit this GitHub page.

2. Authenticate CLI with GitHub:

Run gh auth login in your terminal, follow the on-screen instructions to authenticate your account with the GitHub CLI.

3. Create a New Repository on GitHub Using GitHub CLI

Run the following command, replacing <repo-name> with the desired name for your repository and specifying any other desired options (description, visibility, etc.):

gh repo create <repo-name> --description "<description>" --private

4. Create a Local Repository

  • Navigate to your desired project directory in your terminal.

  • Initialize a Git repository:

git init

5. Create Necessary Files

  • Create the files for your project within the initialized directory.

  • If you are not ready to create your project files you can make a README.md file for your initial commit.

6. Stage Changes

  • Add the created files to the staging area:
 git add .

7. Commit Changes

  • Commit the staged files with a descriptive message:
git commit -m "Initial commit"

8. Add Remote Repository

  • Add the newly created GitHub repository as a remote to your local repository:
git remote add origin https://github.com/<username>/<repo-name>.git

Replace <username> and <repo-name> with your GitHub username and repository name.

9. Push to GitHub

  • Push your local repository to the remote repository:
git push -u origin master

This pushes the master branch to the origin remote (your GitHub repository). The -u flag sets the upstream branch, allowing you to use git push without specifying the branch in the future.

Creating a New Branch and Pushing

  • Create a new branch:
git branch <new_branch_name>

Replace <new_branch_name> with your desired branch name.

  • Switch to the new branch:
git checkout <new_branch_name>
  • Make changes and commit them.

  • Push the new branch to GitHub:

git push -u origin <new_branch_name>