OpenSource Development

Git OpenSource Development

Introduction

Learn basic command like follow
* git init
* git clone
* git branch
* git checkout
* git diff
* git merge
* git add
* git apply & git apply -R

By now you would have learned how to do all basic operations of using git. For OpenSource development, you would need to know these details.

How to setup a git repo?

Quick setup — if you’ve done this kind of thing before

We recommend every repository include a README, LICENSE, and .gitignore.

…or create a new repository on the command line

echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/..yourname../..git
git push -u origin master

…or push an existing repository from the command line

git remote add origin https://github.com/..yourname.../..git
git push -u origin master

 

How to copy a git repo to your local system?

git clone <https://github.com/...yourname..../..git>

 

How to fork a git repo and send a pull request?

Fork a git repo

Fork/ Forking a git repo means taking a copy of repository for yourself. This helps you to do either research on that code for yourself to develop that tool for community & help them fix bugs, add features and enjoy open source development.

Step1: Got to repo you wish to contribution or learn about

Step2: Check for Fork button and click it.

Get your local copy

Step1: Go the folder location where you want to save your code

Step2: Run below command.

clone <your git repo link> <foldername>

Folder name is optional here. From this local repo, you can do all your development.

Pull request

Pull request is a way to send developed code changes to community repo.

Step1: Commit your changes.

Step2: Push code the changes to github repository

Step2: Go to your GitHub repo as shown here (https://youtu.be/G1I3HF4YWEw?t=301)(prefer checking this video) and click check & pull request.

Source: https://www.youtube.com/watch?v=G1I3HF4YWEw

Source: https://www.youtube.com/watch?v=e3bjQX9jIBk [10 mins Introduction]

How to update your forked repo from parent repository?

Background information

I have forked yip module repo from balzss to help him with little development if possible and also learn a bit about open source development. So I have a repo at https://github.com/msampathkumar/yip.git, which you can check. Last night it seems our friend(balzss) did little code clean and over repo is not yet up to date.

Here are the steps of how to update your repo from parent developer repo.
Note:
* parent developer’s(balzss) git repo is at https://github.com/balzss/yip.git
* my git repo is at https://github.com/msampathkumar/yip.git

my prompt looks like below

(env)➜  yip git:(development) ✗
(env)➜  yip git:(development)date
Sun Nov 13 11:41:45 IST 2016

Step1: Check you current repo status

(env)➜  yip git:(development) ✗ git remote -v
origin  https://github.com/msampathkumar/yip.git (fetch)
origin  https://github.com/msampathkumar/yip.git (push)

Step2: Add an upstream link to pull update from parent development code

(env)➜  yip git:(development) ✗ git remote add upstream https://github.com/balzss/yip.git

Step3: Check the if you can see upstream branches

(env)➜  yip git:(development) ✗ git remote -v
origin  https://github.com/msampathkumar/yip.git (fetch)
origin  https://github.com/msampathkumar/yip.git (push)
upstream    https://github.com/balzss/yip.git (fetch)
upstream    https://github.com/balzss/yip.git (push)

Step4: Pull update from parent repo and merge these changes into you master and development branches

Note: I have two branch master and development, So I have to update both of them

(env)➜  yip git:(development) ✗ git fetch upstream
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/balzss/yip
 * [new branch]      develop    -> upstream/develop
 * [new branch]      master     -> upstream/master

Step5: Update your branches with upstream master

(env)➜  yip git:(development) ✗ git branch
* development
  master
(env)➜  yip git:(development) ✗ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
(env)➜  yip git:(master) ✗ git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
(env)➜  yip git:(master) ✗ git merge upsteam/master
merge: upsteam/master - not something we can merge
(env)➜  yip git:(master) ✗ git remote -v
origin  https://github.com/msampathkumar/yip.git (fetch)
origin  https://github.com/msampathkumar/yip.git (push)
upstream    https://github.com/balzss/yip.git (fetch)
upstream    https://github.com/balzss/yip.git (push)
(env)➜  yip git:(master) ✗ git branch
  development
* master
(env)➜  yip git:(master) ✗ git merge upstream/master
Updating f071330..d5c8c59
Fast-forward
 yip | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------
 1 file changed, 81 insertions(+), 64 deletions(-)
(env)➜  yip git:(master) ✗

Step6: Push you local code changes to you home git repo

(env)➜  yip git:(master) ✗ git push
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 822 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/msampathkumar/yip.git
   f071330..d5c8c59  master -> master
(env)➜  yip git:(master) ✗ git branch -a
  development
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/development
  remotes/origin/master
  remotes/upstream/develop
  remotes/upstream/master
(env)➜  yip git:(master) ✗ git pull
Already up-to-date.

Step7: Now update your local development branch also.

(env)➜  yip git:(master) ✗ git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
(env)➜  yip git:(master) ✗ git checkout development
Switched to branch 'development'
Your branch is up-to-date with 'origin/development'.
(env)➜  yip git:(development) ✗ git merge master
Updating d7f2f40..d5c8c59
Fast-forward
 yip | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
(env)➜  yip git:(development) ✗ git pull
Already up-to-date.

Summary:
* Add parent repo to your remote repo
* Merge remote branch master code into your local branch master code
* Update your local branch master code to git repo
* Also update your development branch from your master

Source: https://www.youtube.com/watch?v=-zvHQXnBO6c