Sunday, September 10, 2017

How to sync local repository sources from the github repository?


At times, the local sources repository could be obsolete as the gitgub repository changes after we imported. In this post, I will provide the command required to sync the local repository from the github repository.
babu@babu-VirtualBox:~/EKiD$ git pull origin master
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From https://github.com/babuneelam/EKiD
 * branch            master     -> FETCH_HEAD
   2005d11..46764be  master     -> origin/master
Updating 2005d11..46764be
Fast-forward
 .README.swp | Bin 12288 -> 0 bytes
 README      |  51 ++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 42 insertions(+), 9 deletions(-)
 delete mode 100644 .README.swp
babu@babu-VirtualBox:~/EKiD$


TBD: How are conflicts between local and remote changes handled?


Hope this helps.

How to import from and export changes to an existing github repository?


In this post, I will explain how to import sources from an existing github repository to a local directory, make changes locally as necessary and then export the changes back to the github repository.

  • Import from your github repository to local directory:
  • babu@babu-VirtualBox:~$ git clone https://github.com/babuneelam/EKiD.git
    Cloning into 'EKiD'...
    remote: Counting objects: 54, done.
    remote: Compressing objects: 100% (48/48), done.
    remote: Total 54 (delta 6), reused 46 (delta 4), pack-reused 0
    Unpacking objects: 100% (54/54), done.
    Checking connectivity... done.
    babu@babu-VirtualBox:~$ cd EKiD/
    babu@babu-VirtualBox:~/EKiD$ ls
    ConfigControls  LICENSE  README  SampleOutputs  Sources
    babu@babu-VirtualBox:~/EKiD$ 
  • Make change as necessary
  • See the diff
    • babu@babu-VirtualBox:~/EKiD$ git diff
      diff --git a/ConfigControls/EnvCfg b/ConfigControls/EnvCfg
      index 485a346..63a1976 100644
      --- a/ConfigControls/EnvCfg
      +++ b/ConfigControls/EnvCfg
      @@ -1,5 +1,5 @@
      -GECKO_DRV_PATH=/Users/babuneelam/Downloads/geckodriver
      -FONTS_FOLDER=/Library/Fonts
      +GECKO_DRV_PATH=/home/babu/bin/geckodriver
      +FONTS_FOLDER=/usr/share/fonts/truetype/msttcorefonts/
       #GECKO_DRV_LOG_FILE=RunTimeInfo/geckodriver.log
       #OUTPUT_DIR=RunTimeInfo/output
       #IMAGE_STORE_PATH=RunTimeInfo/google_images
      babu@babu-VirtualBox:~/EKiD$ 
      babu@babu-VirtualBox:~/EKiD$ git diff --name-only
      ConfigControls/EnvCfg
      babu@babu-VirtualBox:~/EKiD$ 
    • Tell git who you are:
          git config --global user.email "you@example.com"
          git config --global user.name "Your Name"
      • TBD: Add/Remove existing files from git repository
      • Export ALL the local changes to the github repository:
            babu@babu-VirtualBox:~/EKiD$ git commit -a
              [master 32a66e9] A few fixes
               2 files changed, 3 insertions(+), 3 deletions(-)
            babu@babu-VirtualBox:~/EKiD$
              babu@babu-VirtualBox:~/EKiD$ git pull origin master
              From https://github.com/babuneelam/EKiD
              * branch            master     -> FETCH_HEAD
              Already up-to-date.

            babu@babu-VirtualBox:~/EKiD$ 
            babu@babu-VirtualBox:~/EKiD$ git push -u origin master
              Username for 'https://github.com': babuneelam
              Password for 'https://babuneelam@github.com':
              Counting objects: 6, done.
              Compressing objects: 100% (6/6), done.
              Writing objects: 100% (6/6), 604 bytes | 0 bytes/s, done.
              Total 6 (delta 4), reused 0 (delta 0)
              remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
              To https://github.com/babuneelam/EKiD.git
                 46764be..32a66e9  master -> master
              Branch master set up to track remote branch master from origin.
            babu@babu-VirtualBox:~/EKiD$ 
      • Export only a few files of the local changes to the github repository:
      babu@babu-VirtualBox:~/EKiD$ git commit ConfigControls/AlgoCfg -m 'Documentation fixes'
      [master 4668ebb] Documentation fixes
      1 file changed, 8 insertions(+)
      babu@babu-VirtualBox:~/EKiD$ git commit ConfigControls/FontCfg -m 'Documentation fixes'
      [master a3437e1] Documentation fixes
      1 file changed, 5 insertions(+), 2 deletions(-)
      babu@babu-VirtualBox:~/EKiD$
      babu@babu-VirtualBox:~/EKiD$ git pull origin master
      From https://github.com/babuneelam/EKiD
      * branch            master     -> FETCH_HEAD
      Already up-to-date.
      babu@babu-VirtualBox:~/EKiD$ git push -u origin master
      Username for 'https://github.com': babuneelam
      Password for 'https://babuneelam@github.com':
      Counting objects: 8, done.
      Compressing objects: 100% (8/8), done.
      Writing objects: 100% (8/8), 1.02 KiB | 0 bytes/s, done.
      Total 8 (delta 3), reused 0 (delta 0)
      remote: Resolving deltas: 100% (3/3), completed with 1 local object.
      To https://github.com/babuneelam/EKiD.git
        b61c9a5..a3437e1  master -> master
      Branch master set up to track remote branch master from origin.

      babu@babu-VirtualBox:~/EKiD$

      Hope this helps.


      How to add collaborators to your github repository?


      Recently, I wanted to invite my friends to collaborate on a project I published on Github. In this post, I will provide steps I used to invite a collaborator for my github repository.
      • Click "Settings" Tab 
      • Click "Collaborators" on left hand side
      • In the text box, search by providing name or github username or email address of the collaborator you want to invite. It automatically displays matching github users. Select correct user from among the drop down entries.
      • Click "Add Collaborator"
      • Now, github sends the invite to the collaborator. Once the collaborator accepts the invite, he/she can start contributing !!


      Hope this helps.

      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



        UA-48797665-1