Javascript required
Skip to content Skip to sidebar Skip to footer

Upload a New File to Github Already Existing Repository

Git Hack: Pushing a New File to an Existing Git Repository

Photograph by Markus Winkler on Unsplash

In that location are a meg things you tin practise with git. Information technology took me a while to realize this. When I started with Git and Github, I would create a repository, button a file at that place, and never visit it. I honestly didn't know what I was doing. I knew I had to push the file there then others could see my lawmaking. It seemed like goose egg more than a storage place: a exam you submitted to be marked.

So I decided to start experimenting, and I started searching for the near efficient way to push files to existing repositories, rather than creating a new repository each time I wanted to push a file.

For this article, I am going to assume the following:

  • You accept Git installed on your arrangement.
  • You have a Github business relationship.
  • You accept set up your business relationship.
  • You take attempted to create a repository on Github and pushed files in that location.

If you have not washed any of the following or you are completely new to Git and Github, you can bank check out this video. It briefly takes yous through all the things I listed in a higher place and more.

Before jumping in, let'south get over a few terms.

What is Git?

Git is a free and open-source distributed version control organisation. It is designed for coordinating work among programmers, just it can be used to rails changes in any gear up of files. In simpler terms, this means different developers can work on the aforementioned projection, make changes offline and on their PCs so merge their work.

What is Github?

GitHub is a Git repository hosting service, but it adds many of its features. While Git is a command-line tool, GitHub provides a Web-based graphical interface.

Github has iii powerful features:

-Fork

-Pull request

-Merge

GitHub allows you to re-create (fork) a repository from one user'due south account to some other. If y'all brand changes you like to share, y'all tin send a notification called a "Pull asking" to the original owner of the repository yous forked. The owner can then merge the changes plant in your repo with the original repo.

A repository (a.thousand.a "repo") is a location where all the files for a item project are stored and you tin can access it with a unique URL. A repository consists of a master branch and tin include multiple branches.

There are three main ways (that I know of) y'all tin can button a new file to an existing repository (endemic by y'all):

  • Linking
  • Cloning
  • Uploading the file directly through Github.

The Cloning and linking methods are very similar, but I adopt the linking method. And this is what I'll be doing.

I would not suggest using the "Upload files" method because there's a limit to the size of files you can upload. But if you are in a hurry and want to upload one or two files, you tin can apply this method.

One time you navigate to your repository, click on "Add file" and select "Upload files."

Uploading directly through Github (footstep 1)

Then you tin either drag and drib a file or choose files from your folder. Don't forget to select "Commit changes" when you are washed to save the changes.

Uploading directly through Github (step ii)

Using my most preferred method of pushing files to an existing Git remote repository:
The beginning matter you demand to do is initialize a git repository in the location of the file you lot want to push. Near times, I move the file to a new folder on my desktop and then open up a Gitbash. You lot can cull to use your Terminal and movement ("cd") to the location of the file. I am going to push button a file called ModifiedGuessingGame.py, which is located in a TestFile folder on my desktop to a remote repository.

git init — To initialize a Git repository in your local folder

Side by side, yous need to link the remote Git repository with the folder on your PC. To do this, click on "Code," re-create the link in the drop-downwards box, caput over to Gitbash, or your Terminal (whichever you are using), and so paste or type it after "git remote add origin."

linking the Git remote repository to the local folder

Subsequently this, pull the remote repo using git pull origin master. Doing this adds all the files in the repository to the local folder of the file you want to add.

All files in the remote repository are now in the local folder

At present that your local folder is linked with the remote repository, you tin can add any new file.

P.S if y'all don't want to add the file to the chief branch, now would exist a good time to git checkout <branch proper noun> to movement to your preferred branch.

git add together ModifiedGuessingGame.py — to add the file

git commit -m "commit file" — to commit changes. After git commit -k you can add whatever comment you desire in the quotes. It doesn't accept to be "commit file."

git push button origin primary — to button the file to the remote repository.

Adding the new file, committing changes and pushing to the remote repository

For the final stride, refresh the page of the repository to encounter if your new file has been added.

ModifiedGuessingGame.py has at present been added to the repository.
That's all you have to do.

barkmanstilad.blogspot.com

Source: https://medium.com/@omoshalewa/git-hack-pushing-a-new-file-to-an-existing-git-remote-repository-574ea735299f