Push existing project into Github

后端 未结 18 756
天涯浪人
天涯浪人 2020-12-04 04:25

I have a folder with my project sources. How I can push this project into Github\'s repository?

I tried using this steps:

  1. I created empty repository o
相关标签:
18条回答
  • 2020-12-04 04:52

    Hate to add yet another answer, but my particular scenario isn't quite covered here. I had a local repo with a history of changes I wanted to preserve, and a non-empty repo created for me on Github (that is, with the default README.md). Yes, you can always re-create the Github repo as an empty repo, but in my case someone else has the permissions to create this particular repo, and I didn't want to trouble him, if there was an easy workaround.

    In this scenario, you will encounter this error when you attempt to git push after setting the remote origin:

     ! [rejected]        master -> master (fetch first)
    error: failed to push some refs to 'git@github.com:<my repo>.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    As the error indicates, I needed to do a git pull after setting the remote origin, but I needed to specify the --allow-unrelated-histories option. Without this option, git pull complains warning: no common commits.

    So here is the exact sequence of commands that worked for me:

    git remote add origin <github repo url>
    cp README.md README.md-save
    git pull origin master --allow-unrelated-histories
    mv README.md-save README.md
    git commit -a
    git push
    
    0 讨论(0)
  • 2020-12-04 04:55

    Create a new repository

    git clone <url>
    cd "repositoryName"
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master
    

    Existing folder

    cd existing_folder
    git init
    git remote add origin <url>
    git add .
    git commit -m "Initial commit"
    git push -u origin master
    

    Existing Git repository

    cd existing_repo
    git remote rename origin old-origin
    git remote add origin <url>
    git push -u origin --all
    git push -u origin --tags
    
    0 讨论(0)
  • 2020-12-04 04:56

    First, make a new repository on Github with your project name.Then follow the below steps..

    1)git init
    2)git add *
    3)git commit -m "first commit"
    4)git remote add origin https://github.com/yuvraj777/GDriveDemo.git
    5)git push -u origin master
    
    0 讨论(0)
  • 2020-12-04 04:56

    Another option if you want to get away from the command line is to use SourceTree.

    Here are some additional resources on how to get set up:

    • Connecting to Bitbucket or Github

    • Cloning a remote repository

    • Creating a local repository

    • Adding an existing local repository

    0 讨论(0)
  • 2020-12-04 04:58

    Git has been the version-control system of choice since its inception in 2005. About 87% of the developers use Git as their version-control system.

    But if you have a project that is already existing and you want to push to Git in the remote server, follow along the below steps:

    1. Go to the terminal of your project directory

    2. You need to initialize your project git using git init

    3. Create a .gitignore file and it is actually a text file that tells Git which files or folders to ignore in a project.

    4. Stage your files using git add .

    5. Commit your changes to your local repository with an appropriate commit message: git commit -m "my first commit"

    6. In this step, you just need to create a repository in any one of the distributed version control systems like GitHub or Bitbucket

    7. Use this Git command to link your local repository with that of the remote: git remote add <your-remote-name> <your-remote-url>

    So, if your GitHub repo-url is https://github.com/your-github-username/new-repository.git, then the Git command becomes:

    git remote add origin https://github.com/<your-github-username>/new-repository.git
    
    1. Push your code to remote GitHub repository

      git push origin master

    Note: The git push command requires two parameters: the name of the remote repository (origin) and the branch to push to (here master is the default branch for every repository).

    Refer this blog for detailed information.

    0 讨论(0)
  • 2020-12-04 04:58

    I found that stimulating an update in "natural" sequence was an easier route than force-pushing things.

    Supposing that the repo is already created on github and you may have also put some stuff into the README.md .

    1. On your computer, open terminal and git clone [repo URL]

    2. You'll see a new folder will have been created bearing your repo's name. Feel free to rename it - doesn't matter.

    3. Move your code, files etc into this folder. Edit the README.md if you have to.

    4. Now open Terminal / command prompt, get inside that folder and do things as if you are making the next update to the repo:

    git add .
    git commit -m "v2"
    git push origin master
    

    Note: at the commit command git may reject, asking to configure the user email and password first. Follow the steps as given on screen, then run the commit command again.

    1. And those three commands is what you do now onwards for every time you want to push another update.
    0 讨论(0)
提交回复
热议问题