Search

Git සහ GitHub කියන්නෙ මොකක්ද? - Developer කෙනෙක් දැනගතම යුතු කරුණු

Git සහ GitHub කියන්නෙ මොකක්ද? - Developer කෙනෙක් දැනගතම යුතු කරුණු

Software field එකේ වැඩ කරන්න නම් Git සහ GitHub ගැන මූලික සංකල්ප සහ commands දැනගැනීම, තේරුම් ගැනීම ඉතා වැදගත් වෙනවා. මේක developer කෙනෙකුගේ basic requirement එකක්. මෙම ලිපියෙන් මගින් ඒවායින් කිහිපයන් ආවරණය කිරීමට බලාපොරොත්තු වෙනවා.

Git කියන්නේ මොකක්ද?

Git කියන්නේ Version Control System එකක්. මේක use කරලා අපිට code changes track කරන්න, code manage කරන්න, team එකක් හෝ කිහිපයක් සමග project එකක් විවිධ කොටස් බෙදාගෙන වැඩ කරන්න පුළුවන්.

Git වල මූලික concepts:

Repository (Repo) - මේක ඔයාගේ project එකේ folder එක. ඔයාගේ code files සහ ඒ files වල history එක මෙතන store වෙනවා. මේක ඔයාගෙ computer එකේ හෝ වෙනත් server computer එකක තියෙන්න පුළුවන්. ඔබේ පරිගණකයේ නම් Local Repo ලෙසද වෙනත් server computer එකක නම් Remote Repo ලෙසද හදුන්වනවා.

Commit - යමි නිශ්චිත වෙලාවක code වල කරන ලද changes වල copy එකක්(snapshot) represent කරනවා. මේ සෑම commit එකකටම unique වු SHA-1 hash code එකක් සහ changes ගැන විස්තර කරන message එකක් තියෙනවා.

Branch - මේක හරියට separate workspace එකක් වගේ, main project එකට කිසිම බලපෑමක් නැතිව වෙනස්කම්, new ideas and features try කරල බලන්න පුළුවන්.

Merge - විවිධ branches වල සිදු කරන ලද code changes එකට එකතු කරන process එක තමා merge කියන්නෙ.

Clone - remote repo එකක copy එකක් ඔයාගෙ local computer එකේ හදාගන්න process එක මේක.

Remote - team එකේ members ලා එයාලගේ changes හුවමාරු කරගන්න use කරන common repository එක remote කියල හදුන්වනවා.

Staging Area(index) - ඔයාගෙ changes ටික commit කරන්න කලින් එවා organize කරන්න, නැවත check කරන්න ලබාදෙන area එක 

GitHub කියන්නේ මොකක්ද?

GitHub කියන්නේ cloud-based platform එකක්. Git repositories online store කරගන්න පුළුවන්(මේක හරියට website එකක් host කරල තියෙන server එකක් වගේ). ඒ වගේම team එකේ අනෙක් developers ලා සමඟ collaborate කරන්නත් පුළුවන්.

GitHub වල main features:

  • Remote Repository - ඔයාගේ local code එක cloud එකේ backup කරන්න පුළුවන්
  • Collaboration - Team එකක project එක share කරගෙන වැඩ කරන්න පුළුවන්
  • Issue Tracking - Bugs සහ features track කරන්න පුළුවන්
  • Pull Requests - Code review කරලා merge කරන්න පුළුවන්

Git Basic Commands

  1. Repository එකක් initialize කරන්න:

    git init

    මේකෙන් ඔයාගේ folder එක Git repository එකක් කරගන්න පුළුවන්.

  2. Staging area එකට files add කරන්න:

    git add filename.txt # Specific file එකක් add කරන්න
    git add filename1.txt filename3.txt filename3.txt  # files කිහිපයක් එකවර add කරන්න
    git add . # ඔක්කොම files add කරන්න
  3. Changes commit කරන්න:

    git commit -m "Your commit message here"

    commit කරද්දි හැම වෙලාවකම short and meaningful message එකක් දෙන්න. Example: "Add login functionality" වගේ.

  4. Repository එකේ status එක බලන්න:

    git status

    මේකෙන් කුමන files change වෙලාද, staged වෙලාද කියලා බලන්න පුළුවන්.

  5. Commit history එක බලන්න:

    git log
  6. Remote repository එක add කරන්න:

    git remote add origin https://github.com/username/repository-name.git
  7. Code එක remote repo එකට(GitHub) push කරන්න:

    git push origin main
  8. Remote repository එකෙන් code pull කරන්න:

    git pull origin main

Practical Example

අපි simple project එකක් සාදන ආකාරය බලමු:

Step 1: Repository එක create කරන්න

mkdir my-first-project
cd my-first-project
git init

Step 2: Simple file එකක් create කරන්න

echo "Hello Git World!" > hello.txt

Step 3: File එක git repo එකට add කරන්න සහ commit කරන්න

git add hello.txt
git commit -m "Add hello.txt file"

Step 4: අලුත් GitHub repository එකක් create කරන්න

  • GitHub.com එකට යන්න
  • GitHub account එකක් නැත්නම් අලුත් account එකක් create කරන්න
  • දැන් එහි ඇති "New" click කරන්න
  • Repository එකට name එකක් දෙන්න
  • "Create Repository" click කරන්න
git-and-github-sinhala.webp
git-and-github-basic-sinhala.webp
git-and-github-basics-sinhala-1.webp

Step 5: Local repository එක GitHub(Remote repository) එක සමඟ connect කරන්න

git remote add origin https://github.com/yourusername/my-first-project.git
git push -u origin main

Git branch සමග වැඩකරන ආකාරය

  • New Branch එකක් Create කරන්න:

    git checkout -b feature-branch
  • Branch Switch කරන්න:

    git checkout main
    git checkout feature-branch
  • Branch Merge කරන්න:

    git checkout main
    git merge feature-branch

Git භාවිතා කිරීමේදී සිදුවන common mistakes සහ ඒවාට solutions

  1. වැරදි commit message එකක් නිවැරදි කිරීම

    git commit --amend -m "Correct message"
  2. Add කරපු file එකක් unstage කරන්න ඕනේ නම්:

    git reset filename.txt
  3. Last commit එක undo කරන්න:

    git reset --soft HEAD~1
  4. Merge Conflicts:

    merge කරද්දි conflicts ආවොත් ඒවා manually අපි හදාගන්න ඕනේ. ඊට පසුව පහත commands භාවිතා කරල commit කරන්න පුළුවන්.

    git add conflicted-file.txt
    git commit -m "Resolve merge conflict"
  5. Accidentally Deleted Files:

    git checkout -- filename.txt
  6. Wrong Branch එකේ Work කරලා:

    git stash
    git checkout correct-branch
    git stash pop

Best Practices

  1. Commit Messages:

    • Clear සහ descriptive වෙන්න ඕනේ
    • Present tense use කරන්න: "Add feature" not "Added feature"
    • 50 characters වලට අඩුවෙන් keep කරන්න
  2. Branching Strategy:

    • main branch එක always stable keep කරන්න
    • Features සහ fixes සඳහා separate branches use කරන්න
    • Branch names descriptive වෙන්න ඕනේ: feature-user-login, fix-payment-bug
  3. Repository Organization:

    • README.md file එකක් add කරන්න
    • .gitignore file එකෙන් unnecessary files ignore කරන්න
    • Code properly comment කරන්න

 

Hushantha Kanakarathna

Hushantha Kanakarathna

Full-stack Developer, Entrepreneur, Co-Founder of Plexxas Solutions (Pvt) Ltd and Founder of Teknyo.lk. Passionate about mobile app development, web development and helping developers grow through innovative solutions and knowledge sharing.


What do you think?

like 0
love 0
haha 0
wow 0
sad 0
angry 0

Leave a comment

Comments 0