Sunday, September 10, 2017

How to add local project sources to a new github repository?



In this post, I will provide steps to publish source code from a local machine to github repository.

  • Create a new GitHub repository. Use "+ --> New Repository" at the top right & the follow the steps there after.
  • In the local machine containing your project source code, open a terminal.
  • Go to the project sources directory.
  • git init (initializes git repository locally)
  • Babus-MacBook-Pro:EKiD babuneelam$ git init
    Initialized empty Git repository in /Users/babuneelam/EKiD/.git/
    Babus-MacBook-Pro:EKiD babuneelam$ 
    • git add . (adds all the files to local git repository)
    • Babus-MacBook-Pro:EKiD babuneelam$ git add .
      Babus-MacBook-Pro:EKiD babuneelam$ 
    • git config --global user.name "Your Name"
    • git config --global user.email you@example.com
    • git commit -m "First Commit" (commits all the code to local repository)
                           Babus-MacBook-Pro:EKiD babuneelam$ git commit -m "First Commit"
                                      Committer: Babu Neelam <babuneelam@Babus-MacBook-Pro.local>
                                      Your name and email address were configured automatically based
                                      on your username and hostname. Please check that they are accurate.
                                      You can suppress this message by setting them explicitly. Run the
                                       following command and follow the instructions in your editor to edit
                                       your configuration file:
                                             git config --global --edit
                                        After doing this, you may fix the identity used for this commit with:
                                             git commit --amend --reset-author
                                      41 files changed, 674 insertions(+)

                                  create mode 100644 .README.swp
                                  ....
                                  .... ....
                         Babus-MacBook-Pro:EKiD babuneelam$ 
    • Go to the Github repository page. In "Clone or download" dropbox, copy the github web url. In my case, it was https://github.com/babuneelam/EKiD.git.
    • In the terminal, git remote add origin <github-web-url>
    • Babus-MacBook-Pro:EKiD babuneelam$ git remote add origin https://github.com/babuneelam/EKiD.git
      Babus-MacBook-Pro:EKiD babuneelam$ 
    • git merge origin/master --allow-unrelated-histories (pulls files from github-web-url to local repository
    • Babus-MacBook-Pro:EKiD babuneelam$ git merge origin/master --allow-unrelated-histories

      Merge made by the 'recursive' strategy.
       .gitignore | 101 +++++++++
       LICENSE    | 674 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2 files changed, 775 insertions(+)
       create mode 100644 .gitignore
       create mode 100644 LICENSE
      Babus-MacBook-Pro:EKiD babuneelam$
    • git push -u origin master (pushes the local project's changes to the github repository)
      Babus-MacBook-Pro:EKiD babuneelam$ git push -u origin master

      Username for 'https://github.com': babuneelam
      Password for 'https://babuneelam@github.com': 
      Counting objects: 43, done.
      Delta compression using up to 4 threads.
      Compressing objects: 100% (41/41), done.
      Writing objects: 100% (43/43), 10.96 MiB | 593.00 KiB/s, done.
      Total 43 (delta 1), reused 0 (delta 0)
      remote: Resolving deltas: 100% (1/1), done.
      To https://github.com/babuneelam/EKiD.git
         b447218..8d823bf  master -> master
      Branch master set up to track remote branch master from origin.
      Babus-MacBook-Pro:EKiD babuneelam$ 
    • Refresh the github repository to see the local changes on the github !!

    Hope this helps.


    References:
    https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
    https://help.github.com/articles/creating-a-new-repository/
    https://stackoverflow.com/questions/38255655/trying-to-pull-files-from-my-github-repository-refusing-to-merge-unrelated-his



    No comments:

    UA-48797665-1