How to upload a project to Github

隐身守侯 提交于 2019-11-26 10:04:43

问题


After checking this question I still have no idea how to get a project uploaded to my Git Hub repository.

I\'m new to Git Hub 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 no where. 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 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.

Thanks in advance :)


回答1:


Since I wrote this answer, 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), means 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. To you 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 commited files:

git push -u origin master




回答2:


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




回答3:


git push --force origin master

if you have problems uploading!




回答4:


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.




回答5:


Here I explain how I did it on Window, maybe it also helps others :)

Make sure to install Git and GitHub.

After installation is complete, open “git bash”;

so a window like below is gonna pop up:

Go ahead and type cd ~ to make sure you are on 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”

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”.

Now go to your C driver; 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:

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

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 youremail@domain.com . 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 :)




回答6:


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



回答7:


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 project from scratch require git pull origin master.

5) git pull origin master

6) git push origin master

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




回答8:


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 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: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/




回答9:


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 GitBash.

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.

Hope my answer helped.




回答10:


I think the easiest thing for you to do would be to install the git plugin for eclipse, works more or less the same as eclipse CVS and SVN plugins:

http://www.eclipse.org/egit/

GL!




回答11:


  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



回答12:


Probably the most useful thing you could do is to peruse the online book [http://git-scm.com/book/en/]. It's really a pretty decent read and gives you the conceptual context with which to execute things properly.




回答13:


Download SourceTree. It is available for windows7+ and Mac and is highly recommend to upload files on github via interactive UI.




回答14:


  1. First You have to create an account on Github
  2. Then create new Project - name that Project as you want then your project url is shown
  3. Now copy the url
  4. Then open 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, Repository is successfully uploaded.

For Complete guidance, you can watch this video.




回答15:


Follow the instruction from RishiKesh Pathak above, 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.




回答16:


The best way to 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 codeAcademy




回答17:


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




回答18:


It took me like 2 hours to realize that I'm supposed to create Repo to GitHub (http://github.com/new) before trying to push my local files to github.

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. I just thought that my repo will be created automatically during the first push. I was so wrong.




回答19:


  1. We need Git Bash
  2. In Git Bash Command Section::

1.1 ls

It will show you default location.

1.2 CD "C:\Users\user\Desktop\HTML" We need to assign project path

1.3 git init It will initialize the empty git repository in C:\Users\user\Desktop\HTML

1.4 ls It will list all files name

1.5 git remote add origin https://github.com/repository/test.git it is your https://github.com/repository/test.git is your repository path

1.6 git remote -v To check weather we have fetch or push permisson or not

1.7 git add . If you put . then it mean whatever we have in perticular folder publish all.

1.8 git commit -m "First time"

1.9 git push -u origin master




回答20:


for uploading a new project into GIT (first you need to have local code base of project and the GIT repo where you will be uploading project ,in GIT you need to have your credentials)

  1. List item

    1.open Git Bash

    2 . 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

    1. git init press enter then you will see something like this below Initialized empty Git repository in *:/***/****/*****/.git/ so git init will initialize the empty GIT repository at local
    2. git add . press enter the above command will add all the directory,sub directory , 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. warning: LF will be replaced by CRLF in ********. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in *******. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in ********. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in *******. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in **************. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in ************. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in *************** The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in j*******. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in ***********. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in **************. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in ***********. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in *********. The file will have its original line endings in your working directory.

    3. git commit -m "first commit" press enter -m provided option for adding comment it will commit the code to stage env 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. warning: LF will be replaced by CRLF in *******. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in ********. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in *********. The file will have its original line endings in your working directory.

warning: LF will be replaced by CRLF in ***********.


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

6.git remote add origin http://username@git:repopath.git press enter this will add to repo

7.git push -u origin master press enter this will upload all from local to repo in this step you need to enter password for the repo 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.



来源:https://stackoverflow.com/questions/12799719/how-to-upload-a-project-to-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!