How to upload a project to GitHub

UploadGithubRepositoryGit BashGit Gui

Upload Problem Overview


After checking How can I upload my project's Git repository to GitHub?, I still have no idea how to get a project uploaded to my GitHub repository.

I'm new to GitHub and I have no idea what to do. I created a repository, but I want to upload my project to it.

I've looked on the repository page for an upload button of some kind, but I haven't seen anything of the sort.

I've looked at the links provided so far, but I'm still getting nowhere. They mention command line; is that Windows command line or Git Bash? Because I can't get either to do anything.

I also tried using the Git GUI, but when I select the folder I want it says that it's not a Git repository...does it need to be zipped up? I tried adding the .gitconfig file in the folder, but it doesn't make a difference.

Upload Solutions


Solution 1 - Upload

GitHub released a native Windows client which makes all the below steps redundant.

You can also use Sourcetree to get both Git and Mercurial setup on Windows.


Here is how you would do it in Windows:

  1. If you don't have Git installed, see this article on how to set it up.

  2. Open up a Windows command prompt.

  3. Change into the directory where your source code is located in the command prompt.

  4. First, create a new repository in this directory git init. This will say "Initialized empty git repository in ....git" (... is the path).

  5. Now you need to tell Git about your files by adding them to your repository. Do this with git add filename. If you want to add all your files, you can do git add .

  6. Now that you have added your files and made your changes, you need to commit your changes so Git can track them. Type git commit -m "adding files". -m lets you add the commit message in line.

So far, the above steps is what you would do even if you were not using GitHub. They are the normal steps to start a Git repository. Remember that Git is distributed (decentralized), meaning you don't need to have a "central server" (or even a network connection), to use Git.

Now you want to push the changes to your Git repository hosted with GitHub. You do this by telling Git to add a remote location, and you do that with this command:

git remote add origin https://github.com/yourusername/your-repo-name.git

*Note: your-repo-name should be created in GitHub before you do a git remote add origin ...

Once you have done that, Git now knows about your remote repository. You can then tell it to push (which is "upload") your committed files:

git push -u origin master

Solution 2 - Upload

How to upload a project to GitHub from scratch

Follow these steps to project to GitHub:

  1. git init

  2. git add .

  3. git commit -m "Add all my files"

  4. git remote add origin https://github.com/yourusername/your-repo-name.git

    > Upload of project from scratch require git pull origin master.

  5. git pull origin master

  6. git push origin master

Solution 3 - Upload

git push --force origin master

if you have problems uploading!

Solution 4 - Upload

Here I explain how I did it on Windows.

Make sure to install Git and GitHub.

After installation is complete, open Git Bash.

Enter image description here

So a window like below is going to pop up:

Enter image description here

Go ahead and type cd ~ to make sure you are in the home directory. You can check the address that you are in it by typing pwd;

Now you need to create a GitHub account. After creating a GitHub account, go ahead and sign in.

After you signed in, on the top right click on the + and choose “New Repository”

Enter image description here

Then in the opened window, type the name that you wish to have for the repository in the “Repository name” box. Add “Description (optional)” if you like, and mark “Initialize this repository with a README”. Then click on “Create repository”.

Enter image description here

Now go to your C drive; create a new folder and name it “git”. Now go to the “Git Bash” window; change the directory to c drive by typing cd ~; cd /c. If you type ls there it would show you the folders there. Make sure it shows the Git folder there:

Enter image description here

Now go back to the browser; go to your GitHub page, click on the repository that you made, click on “Clone or download”, and copy the address that shows there (by choosing copy to clipboard).

Enter image description here

Now going back to “Git Bash”. Use the command cd git to go to the git folder; now write the following commands to connect to your GitHub (enter the username and password of your GitHub when it asks you):

git config --global user.name "Your Name"

And then: git config --global user.email [email protected].

Next type: git clone (URL), instead of the (URL), type the address of the GitHub repository that you copied from your GitHub page; (e.g., git clone https://github.com/isalirezag/Test.git).

Now if you do ls command you will see your repository there. If you also open the Git folder that you have in your window you will see that your repository is added as a folder.

Now use the cd command to go to the repository: cd Test

Go ahead and copy and paste any files that you want to put in this repository in that folder.

In order to transfer the files to your repository you need to do following now:

Type git

add filename (filename is the file name that you want to upload) or you can type the command below if you want to add all the files in the folder:

git add .

Then type: git commit -m "adding files". And then: git push -u origin master .

And then you should be all set. If you refresh your GitHub account, the files should be there :)

Solution 5 - Upload

Follow these steps to upload your project to GitHub:

  1. git init

  2. git add .

  3. git commit -m "Add all my files"

  4. git remote add origin https://github.com/yourusername/your-repo-name.git

Upload of the project from scratch requires git pull origin master.

  1. git pull origin master

  2. git push origin master

If any problem occurs in pushing, use git push --force origin master.

Solution 6 - Upload

Follow these two steps:

  1. Create the repository online using the link: https://github.com/new
  2. Then link your local repo to the remote repo using the command: git add remote origin https://github.com/userName/repo.git Here the repo.git will be your newly created remote repo.

This will work like a charm. No need to worry about the SSH or HTTPS ways. I first faced the same issue and spent hours for solution. But this worked for me.

Solution 7 - Upload

Easy-to-follow steps: git pull origin master or main will give a fatal error:

> Couldn't find remote ref main

So below steps will work just fine.

  1. git init
  2. git add .
  3. git commit -m "initial commit"
  4. git remote add origin https://github.com/yourusername/your-repo-name.git
  5. git branch -M main
  6. git push -u origin main

Solution 8 - Upload

This worked for me;

1- git init
2- git add .
3- git commit -m "Add all my files"
4- git remote add origin https://github.com/USER_NAME/FOLDER_NAME
5- git pull origin master --allow-unrelated-histories
6- git push origin master

Solution 9 - Upload

> Create a new repository on GitHub. To avoid errors, do not initialize > the new repository with README, license, or gitignore files. You can > add these files after your project has been pushed to GitHub. Open > Terminal (for Mac users) or the command prompt (for Windows and Linux > users). > > Change the current working directory to your local project. > > Initialize the local directory as a Git repository. > > git init
> #Add the files in your new local repository. This stages them for the first commit.

> > git add
># Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'. Commit the files that you've staged in your local repository.

> git commit -m 'First commit'
> #Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git > reset --soft HEAD~1' and commit and add the file again.

> 1. At the top of your GitHub repository's Quick Setup page, click enter image description here to copy the remote repository URL. At the top of your GitHub repository's Quick Setup > page, click to copy the remote repository URL. > 2. In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

>$ git remote add origin remote repository URL ># Sets the new remote git remote -v ># Verifies the new remote URL Note: GitHub for Windows users should use the command git remote set-url origin instead of git remote add origin here. Push the changes in your local repository to GitHub.

>$ git push origin master
># Pushes the changes in your local repository up to the remote repository you specified as the origin.

Source attribution: Adding an existing project to GitHub using the command line

Solution 10 - Upload

I assume you are on a Windows system like me and have Git installed. You can either run these commands by simple command prompt in the project directory or you can also use Git Bash.

Step 1:

Create a repository in Git manually. Give it whatever name you seem fit.

Step 2:

Come to your local project directory. If you want to publish your code to this new repository you just created, make sure that in the projects root directory there is no folder name .git. If there is, delete it. Run command git init.

Step 3:

Run command

git add .

Step 4:

Run command

git commit -m YourCommitName

Step 5:

Run command

git remote add YourRepositoryName https://github.com/YourUserName/YourRepositoryName.git

Step 6:

Run Command

git push --set-upstream YourRepositoryName master --force

Please note that I am using the latest version of Git at the time of writing. Also note that I did not specify any particular branch to push the code into so it went to master. In step 6 the Git will ask you to authorize the command by asking you to enter username and password in a popup window.

Solution 11 - Upload

  1. Open Git Bash.
  2. Change the current working directory to your local project.
  3. Initialize the local directory as a Git repository: $ git init
  4. Add the files in your new local repository. This stages them for the first commit: $ git add .
  5. Commit the files that you've staged in your local repository: $ git commit -m "First commit"
  6. At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
  7. In the Command prompt, add the URL for the remote repository where your local repository will be pushed : $ git remote add origin remote repository URL
  8. Push the changes in your local repository to GitHub: $ git push origin master

Solution 12 - Upload

Steps to upload project to Git:

Step 1 - open cmd and change the current working directory to your project location.

Step 2 - Initialize your project directory as a Git repository.

git init

Step 3 - Add files in your local repository.

add .

Step 4 - Commit the files that you've staged in your local repository.

git commit -m "First commit"

Step 5 - Copy the remote repository URL.

Step 6 - Add the remote repository URL as origin in your local location.

git add origin copied_remote_repository_url

Step 7 - Confirm your origin is updated or not.

git remote show origin

Step 8 - Push the changed to your GitHub repository

git push origin master.

Solution 13 - Upload

I think the easiest thing for you to do would be to install the Git plugin for Eclipse. It works more or less the same as the Eclipse CVS and SVN plugins.

Solution 14 - Upload

  1. First you have to create an account on GitHub

  2. Then create a new project - name that project as you want and then your project URL is shown

  3. Now copy the URL

  4. Then open a Command Prompt and go to the directory or folder which you want to upload using cmd

  5. Then type the following commands

      git init
      git add .
      git commit -m "initial commit"
      git remote add origin PASTE URL
      git push -u origin master
    
  6. Now check your GitHub account. The repository is successfully uploaded.

For complete guidance, you can watch this video.

Solution 15 - Upload

It took me like 1-2 hours to realize that I'm supposed to create the repository at GitHub before trying to push my local files to GitHub (or whatever, Git service you're using).

After trying to push, errors were like:

remote: Repository not found.
fatal: repository 'https://github.com/username/project.git/' not found

I feel like an idiot, but I really would like to emphasize this for beginners like me. I just thought that my repository will be created automatically during the first push. I was so wrong.

You can see your remotes with this command:

git remote -v

Solution 16 - Upload

Probably the most useful thing you could do is to peruse the online book Pro Git. It's really a pretty decent read and gives you the conceptual context with which to execute things properly.

Solution 17 - Upload

Follow the instructions from RishiKesh Pathak. You can even short the push command by inserting this command line one time only:

git config --global push.default simple

So next time instead of using git push origin master you just need:

git push

See details here.

Solution 18 - Upload

Download Sourcetree.

It is available for Windows 7 (and later) and Mac, and it is highly recommended to upload files on GitHub via the interactive UI.

Solution 19 - Upload

Make sure that Git is installed on your system. I'm explaining the process using windows OS [Although it shouldn't be OS dependent job]

Here is how I did:

  1. Open the cmd (you can do with git bash as well if you've installed git bash).

  2. Go to your project directory (where your project is located, it's essentially changing to directory either usiing cd path or through manual folder navigation).

  3. Now type git init. This will initialize an empty repository if it is first time and Enter.

    For example: git init

  4. Now type git add <filename>(if specific file) or git add <filename1> <filename2> <filenameN> (if specific but more than one files) or git add . (if you want to add all files) and enter.

  5. Now type git commit -m "commit message goes here" and enter.

    (in case if you need to check the status you can do by typing git status) and enter.

  6. Now type git remote add origin git_repository_url

    (check git remote -v go check remote repository) and Enter.

  7. Now it's turn to push it to the remote repository [essentially taking all the changes from local git to cloud(github) ...git push origin master and enter

    (if you get error you push it forcefully by typing ...git push -f origin master and enter.

NOTE : master is the name of your master branch. If you've multiple branches, make sure that you select the name of the branch accordingly.

Now you're done with adding it to your remote repository from local computer. Refresh it and it will be there in your created repository's selected branch.

Solution 20 - Upload

The best way to use Git is to actually start Gitting. Try out this website which makes you go step by step on what are the essential ways for performing functions on command line for pushing a project on GitHub.

This is called try.github.io or you could also take up a course on Codecademy.

Solution 21 - Upload

I did as follows;

  1. git init
  2. git add .
  3. git commit -m "Your_message"
  4. git remote add origin @your_git_repository
  5. git push -u origin master

Of course you have to install Git.

Solution 22 - Upload

  1. We need Git Bash

  2. In the Git Bash Command Section:

    1. ls

      It will show your default location.

    2. CD "C:\Users\user\Desktop\HTML"

      We need to assign the project path.

    3. git init

      It will initialize the empty Git repository in C:\Users\user\Desktop\HTML

    4. ls

      It will list all file names.

    5. git remote add origin https://github.com/repository/test.git

      It is your https://github.com/repository/test.git is your repository path

    6. git remote -v

      To check whether we have fetch or push permission or not

    7. git add .

      If you use . then it means whatever we have in the particular folder publish all.

    8. git commit -m "First time"

    9. git push -u origin master

Solution 23 - Upload

You need an SSH connection and GitHub init into your project. I will explain under Linux machine.

Let's start with some easy stuff: navigate into your project in the terminal, and use:

git init
git add .
git commit

Now let's add SSH into your machine:

use

ssh-keygen -t rsa -C "[email protected]"

Copy the public key, and then add it to your GitHub repository:

Deploy keys -> add one

Back to your machine project, now launch:

git push origin master

if there is an error, configure your .github/config file by

nano .github/config

And change the URL to the SSH one by:

url = [email protected]:username/repo....

And that's it.

Solution 24 - Upload

Try using Git Bash to push your code/make changes instead of uploading files directly on GitHub (it is less prone to errors and is quite comfortable at times - takes less time as well!). For doing so, you may follow the below given steps:

  1. Download and install the latest version of Git Bash from here.
  2. Right-click on any desired location on your system.
  3. Click “Git Bash Here”.
  4. git config --global user.name “your name”
  5. git config --global user.email “your email”
  6. Go back to your GitHub account – open your project – click on “clone” – copy HTTPS link.
  7. git clone PASTE HTTPS LINK.
  8. A clone of your GitHub project will be created on your computer location.
  9. Open the folder and paste your content.
  10. Make sure content is not empty.
  11. Right-click inside the cloned folder where you have pasted your content.
  12. Click “Git Bash Here” again.
  13. You will find (master) appearing after your location address.
  14. git add .
  15. Try git status to check if all your changes are marked in green.
  16. git commit --m “Some message”
  17. git push origin master

Solution 25 - Upload

For uploading a new project into Git (first you need to have the local code base of the project and the Git repository where you will be uploading project. In Git, you need to have your credentials).

  1. List item

  2. Open Git Bash

  3. Go to the directory where you have the code base (project location)

    cd to project location

    cd ////**

    Then here you need to execute Git commands.

  4. git init

    Press Enter then you will see something like this below.

    The initialized empty Git repository in ://****/***/.git/, so git init will initialize the empty Git repository at local

  5. git add .

    Press Enter

    The above command will add all the directories, subdirectories, files, etc.

    You will see something like this:

    > warning: LF will be replaced by CRLF in **************.
    > The file will have its original line endings in your working directory.

  6. git commit -m "first commit"

    Press Enter. -m provided option for adding comment.

    It will commit the code to the stage environment.

    You will see some thing like this:

    > [master (root-commit) 34a28f6] adding ******** > warning: LF will be replaced by CRLF in c*******. > The file will have its original line endings in your working directory.

    > -------- > ---------- > 27 files changed, 3724 insertions(+) > create mode 100644 ***** > create mode 100644 ***** > create mode 100644 *****

  7. git remote add origin

    http://username@git:repopath.git

    Press Enter. This will add to the repository.

  8. git push -u origin master

    Press Enter.

    This will upload all from local to repository in this step you need to enter password for the repository where you will be uploading the code.

    You will see some thing like this below:

    > Counting objects: 33, done.
    > Delta compression using up to 12 threads.
    > Compressing objects: 100% (32/32), done.
    > Writing objects: 100% (33/33), 20.10 KiB | 0 bytes/s, done.
    > Total 33 (delta 14), reused 0 (delta 0)
    > To http://username@git:repolocation.git
    > * [new branch] master -> master
    > Branch master set up to track remote branch master from origin.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjampez77View Question on Stackoverflow
Solution 1 - UploadBurhan KhalidView Answer on Stackoverflow
Solution 2 - UploadRishiKesh PathakView Answer on Stackoverflow
Solution 3 - UploadsonuView Answer on Stackoverflow
Solution 4 - UploadAlexView Answer on Stackoverflow
Solution 5 - UploadAli Yar KhanView Answer on Stackoverflow
Solution 6 - UploadVinayBSView Answer on Stackoverflow
Solution 7 - UploadTinyiko ChaukeView Answer on Stackoverflow
Solution 8 - UploadWalid BoussetaView Answer on Stackoverflow
Solution 9 - UploadRakeshView Answer on Stackoverflow
Solution 10 - UploadAbhay ShiroView Answer on Stackoverflow
Solution 11 - UploadFelhi AbdelhafidhView Answer on Stackoverflow
Solution 12 - UploadMandeep Singh GillView Answer on Stackoverflow
Solution 13 - UploadEvaView Answer on Stackoverflow
Solution 14 - Uploadmitesh7172View Answer on Stackoverflow
Solution 15 - UploadO-9View Answer on Stackoverflow
Solution 16 - UploadProfVersaggiView Answer on Stackoverflow
Solution 17 - UploadeQ19View Answer on Stackoverflow
Solution 18 - UploadPrakhar1001View Answer on Stackoverflow
Solution 19 - UploadBadri PaudelView Answer on Stackoverflow
Solution 20 - UploadShan-DesaiView Answer on Stackoverflow
Solution 21 - UploadCansel MutiView Answer on Stackoverflow
Solution 22 - UploadRahul GangaharView Answer on Stackoverflow
Solution 23 - UploadNimr SawaftaView Answer on Stackoverflow
Solution 24 - UploadTanvi PenumudyView Answer on Stackoverflow
Solution 25 - UploadPrem SView Answer on Stackoverflow