DEV Community

Cover image for How to add files to your GitHub repository
Jeff Omenyuru
Jeff Omenyuru

Posted on

How to add files to your GitHub repository

You can add files to your repository from GitHub or the command line in Git. Use GitHub if the file you’re adding is anything below 25MB. But if it does exceed 25MB, you might want to use the command line. You can add a file of up to 100MB using the command line.

In this How-to guide, you’ll learn how to add files to your repository from GitHub and the command line.

Add files to your repository from GitHub

(1) Open your GitHub profile and go to the repository to which you want to add the files.

(2) Click Add file to reveal a drop-down.

(3) Click Upload files in the drop-down.

Create new file screenshot

(4) Pick, drag, and release the files in the area below. Or click choose your files to upload directly from your local machine.

Drag files to GitHub

(5) In the comment box, write your commit message. At this point, you can either commit directly to the master branch or create a new branch and start a pull request. It’s not a good practice to commit changes directly to the main branch, especially when you aren’t working solo. You can click Learn more about pull requests for more information.

Commit message screenshot

(6) Click Commit changes.

Add files to your repository from the command line

This guide assumes you’ve installed and set up Git on your computer.

(1) On GitHub, navigate to the repository to which you want to add a file and open it.

(2) Highlight the HTTPS link and copy.

Link copy screenshot

(3) Open Git Bash on your computer.

(4) Enter cd ~/Name of the location where you want your cloned repository. I chose “Desktop” as the preferred destination in the image below.

Desktop

(5) Type "git clone" and paste the link you copied from GitHub.

Git clone screenshot

(6) Press enter.

Done cloning screenshot

(7) Move the files of your choice into the local directory created when you cloned the repository.

(8) Change your current working directory to your local repository, manually or from the command line in Git Bash. To do this from the command line, enter cd ~/Desktop/Exercise in Git Bash and press enter. Replace “Exercise” with the name of your local directory.

Master screenshot

(9) To stage the files for commit to your local repository, enter git add .. To check the status, enter git status and press enter (git status gives you a view of the staged files).

Git status screenshot

(10) To commit the file in your local repository, enter git commit -m “Commit message”.

Git commit screenshot

(11) To push changes from your local repository to your remote repository on GitHub, enter git push origin your branch name.

Git Push

(12) Navigate to GitHub and check out your new file.

Discussion (0)