How to upload a project to Github

2019-01-08 03:07发布

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 :)

17条回答
唯我独甜
2楼-- · 2019-01-08 03:07

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.

查看更多
乱世女痞
3楼-- · 2019-01-08 03:08

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.

查看更多
Anthone
4楼-- · 2019-01-08 03:13

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

查看更多
可以哭但决不认输i
5楼-- · 2019-01-08 03:13

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

查看更多
姐就是有狂的资本
6楼-- · 2019-01-08 03: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.

查看更多
Bombasti
7楼-- · 2019-01-08 03:16

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

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

查看更多
登录 后发表回答