Upload Files to Git Repository Command Line Linux

GitHub is simply a cloud-hosted Git management tool. Git is distributed version control, meaning the entire repo and history lives wherever you put it. People tend use GitHub though in their concern or development workflow equally a managed hosting solution for backups of their repositories.

It's a convenient and mostly worry-free method for bankroll up all your code repos. Information technology as well allows y'all to very nicely navigate and view your lawmaking on the web. GitHub takes this even farther by letting yous connect with coworkers, friends, organizations, and more.

Prerequisites:

To initialize the repo and push button information technology to GitHub you'll need:

  1. A free GitHub Account
  2. git installed on your local auto

Step 1: Create a new GitHub Repo

Sign in to GitHub and create a new empty repo page. You lot can choose to either initialize a README or not. It doesn't really affair because we're merely going to override everything in this remote repository anyways.

Create new GitHub Repo

Through the balance of this tutorial we'll assume your GitHub username is sammy and the repo you created is named my-new-project (So yous'll need to swap those out with your bodily username and repo name when copy/pasting commands)

Step 2: Initialize Git in the project folder

From your terminal, run the following commands after navigating to folder you would similar to add:

Initialize the Git Repo

Brand sure you are in the root directory of the project you desire to push to GitHub and run:

Note: if yous already take an initialized Git repository, y'all tin skip this control

                      
  1. git init

This step creates a subconscious .git directory in your projection folder which the git software recognizes and uses to store all the metadata and version history for the project.

Add the files to Git index

                      
  1. git add -A

The git add control is used to tell git which files to include in a commit, and the -A argument means "include all".

Commit Added Files

                      
  1. git commit -m 'Added my projection'

The git commit command creates a new commit with all files that have been "added". the -m 'Added my project' is the message that will be included alongside the commit, used for future reference to understand the commit.

Add new remote origin (in this case, GitHub)

                      
  1. git remote add origin git@github.com:sammy/my-new-project.git

Note: Don't forget to replace the highlighted $.25 in a higher place with your username and repo name.

In git, a "remote" refers to a remote version of the same repository, which is typically on a server somewhere (in this case GitHub.) "origin" is the default proper name git gives to a remote server (you can have multiple remotes) so git remote add origin is instructing git to add the URL of the default remote server for this repo.

Button to GitHub

                      
  1. git push -u -f origin main

With this, there are a few things to annotation. The -f flag stands for force. This volition automatically overwrite everything in the remote directory. We're only using information technology here to overwrite the README that GitHub automatically initialized. If yous skipped that, the -f flag isn't actually necessary.

The -u flag sets the remote origin as the default. This lets y'all later on easily just do git push and git pull without having to specifying an origin since we always want GitHub in this instance.

All together

                      
  1. git init
  2. git add -A
  3. git commit -g 'Added my projection'
  4. git remote add origin git@github.com:sammy/my-new-project.git
  5. git push button -u -f origin master

Decision

Now you are all set to rail your code changes remotely in GitHub! Every bit a next step hither'due south a complete guide to how to use git

Once you start collaborating with others on the project, you lot'll want to know how to create a pull asking.

freemanamust1957.blogspot.com

Source: https://www.digitalocean.com/community/tutorials/how-to-push-an-existing-project-to-github

0 Response to "Upload Files to Git Repository Command Line Linux"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel