Translate

Friday, 16 January 2026

Git, branching

 In Git, branching is like creating a parallel version of your project. It allows you to "branch off" from the main code to work on a new feature or fix a bug without messing up the stable version everyone else is using.

Git branching in telugu


Think of it like a tree: the main branch is the trunk, and every time you want to try something new, you grow a side branch. Once you’re happy with your work, you can "merge" that branch back into the trunk.


Basic Example 1: Creating a New Feature

Imagine you are building a website and want to add a "Contact Us" page. You don't want to break the homepage while you're still writing the code for the new page.

  1. Create a branch: You create a branch called add-contact-page.

  2. Work in isolation: You write your HTML and CSS on this branch. The main branch stays exactly as it was.

  3. Merge: Once the contact page is perfect, you merge the add-contact-page branch into main. Now, the live website has the new feature.

Basic Example 2: Fixing an Urgent Bug (Hotfix)

Suppose your website is live, and someone discovers that the "Sign Up" button is broken. You are currently in the middle of a big 2-week project on a different branch.

  1. Switch to Main: You quickly switch back to the main branch (the stable code).

  2. Create a Hotfix branch: You create a temporary branch called fix-signup-button.

  3. Fix and Deploy: You fix the bug on this tiny branch and merge it immediately back into main.

  4. Resume Work: You switch back to your long-term project branch and continue where you left off. The bug is fixed, and your big project was never interrupted.


Core Commands to Know

  • git branch <name>: Creates a new branch.

  • git checkout <name> (or git switch <name>): Moves you onto that branch.

  • git merge <name>: Combines the work from one branch into your current one.

  • git branch: Lists all the branches in your project.

-------------

Here is the complete list of Git branching commands organized by their logical order in a typical development workflow.


1. Viewing Branches (Inspection)

Before you start working, you need to see which branches exist and where you are currently.

  • git branch: Lists all local branches. The branch marked with an asterisk * is the one you are currently on.

  • git branch -v: Shows the last commit message on each branch.

  • git branch -a: Lists all branches, including remote branches (those on GitHub/GitLab).

2. Creating and Moving (Navigation)

These commands are used when you want to start a new task or switch between existing tasks.

  • git branch <name>: Creates a new branch but keeps you on your current branch.

  • git switch <name>: Moves you from your current branch to the specified branch.

  • git switch -c <name>: (Highly Recommended) Creates a new branch and switches to it immediately. (This is the modern alternative to git checkout -b).

3. Renaming (Maintenance)

Useful if you made a typo or want to give a branch a more descriptive name.

  • git branch -m <new-name>: Renames the branch you are currently on to the new name.

4. Integrating Changes (Merging)

Once your work on a feature branch is finished and tested, you bring it back to the main code.

  • git merge <name>: Combines the history and changes of the specified branch into your current branch.

    Note: Usually, you switch to main first and then run git merge feature-branch.

5. Cleaning Up (Deleting)

To keep your project tidy, you should delete branches after they have been merged.

  • git branch -d <name>: Deletes the branch only if it has already been merged into your current branch (Safe delete).

  • git branch -D <name>: Force deletes the branch even if the changes aren't merged yet (Use with caution!).

6. Syncing with the Server (Remote)

These commands share your local branches with others or delete them from the server.

  • git push origin <name>: Uploads your local branch to the remote repository (GitHub).

  • git push origin --delete <name>: Deletes the branch from the remote server.


Summary Table

StepCommandWhat it does
1. Viewgit branchShows all local branches.
2. Create & Gogit switch -c <name>Creates a new branch and enters it.
3. Renamegit branch -m <new-name>Changes the name of the current branch.
4. Switchgit switch <name>Switches to an existing branch.
5. Combinegit merge <name>Merges changes into the current branch.
6. Deletegit branch -d <name>Removes a local branch after merging.
7. Pushgit push origin <name>Sends your branch to the online server.


--------------

Gitలో Branching (బ్రాంచింగ్) అంటే మీ ప్రాజెక్ట్‌కి ఒక సమాంతర వెర్షన్‌ను (Parallel version) సృష్టించడం. అంటే, అసలైన కోడ్ (Main code) ఏమాత్రం పాడవకుండా, మీరు కొత్త మార్పులను ఒక విడి భాగంలో చేసుకునే వెసులుబాటు ఇది.

దీన్ని ఒక చెట్టులా ఊహించుకోండి: Main branch అనేది చెట్టు కాండం (Trunk) లాంటిది. మీరు ఏదైనా కొత్త ఫీచర్ యాడ్ చేయాలనుకున్నప్పుడు ఒక కొమ్మ (Branch) లాగా విడిపోయి పని చేస్తారు. ఆ పని పూర్తయ్యాక, ఆ కొమ్మను తిరిగి కాండంతో కలిపేస్తారు (Merge).


ఉదాహరణ 1: కొత్త ఫీచర్ యాడ్ చేయడం (Creating a New Feature)

మీరు ఒక వెబ్‌సైట్ తయారు చేస్తున్నారు అనుకుందాం. ఇప్పుడు దానికి "Contact Us" అనే కొత్త పేజీని చేర్చాలి.

  1. కొత్త బ్రాంచ్: మీరు add-contact-page అనే పేరుతో ఒక బ్రాంచ్ క్రియేట్ చేస్తారు.

  2. విడిగా పని చేయడం: మీరు మీ కోడింగ్ అంతా ఈ కొత్త బ్రాంచ్‌లోనే చేస్తారు. దీనివల్ల మెయిన్ వెబ్‌సైట్ (Main branch) కి ఎటువంటి ఇబ్బంది ఉండదు. అది ఎప్పటిలాగే పని చేస్తూ ఉంటుంది.

  3. కలపడం (Merge): మీ పని పర్ఫెక్ట్‌గా ఉందని నిర్ధారించుకున్నాక, ఈ బ్రాంచ్‌ను main బ్రాంచ్‌లో కలిపేస్తారు. ఇప్పుడు మీ వెబ్‌సైట్‌లో కొత్త పేజీ కనిపిస్తుంది.

ఉదాహరణ 2: అర్జెంట్ బగ్ ఫిక్స్ (Hotfix for a Bug)

మీ వెబ్‌సైట్ లైవ్‌లో ఉంది, కానీ హఠాత్తుగా "Sign Up" బటన్ పని చేయడం లేదని తెలిసింది. మీరు అప్పటికే వేరే పెద్ద ప్రాజెక్ట్ పనిలో బిజీగా ఉన్నారు.

  1. మెయిన్ బ్రాంచ్‌కి మారడం: మీరు చేస్తున్న పనిని ఆపి, వెంటనే స్థిరంగా ఉన్న main బ్రాంచ్‌కి వెళ్తారు.

  2. బగ్ ఫిక్స్ బ్రాంచ్: వెంటనే fix-signup-button అనే ఒక చిన్న బ్రాంచ్ క్రియేట్ చేస్తారు.

  3. రిపేర్ & డిప్లాయ్: ఆ బటన్‌ను ఫిక్స్ చేసి, వెంటనే దాన్ని main బ్రాంచ్‌లో కలిపేస్తారు. తద్వారా లైవ్ వెబ్‌సైట్ సెట్ అయిపోతుంది.

  4. పాత పనిలోకి: ఇప్పుడు మళ్ళీ మీరు ఆగిపోయిన మీ పాత ప్రాజెక్ట్ బ్రాంచ్‌లోకి వెళ్లి పని కొనసాగించవచ్చు.


ముఖ్యమైన కమాండ్స్ (Core Commands)

  • git branch <name>: కొత్త బ్రాంచ్ సృష్టించడానికి.

  • git checkout <name> (లేదా git switch <name>): ఒక బ్రాంచ్ నుండి ఇంకో బ్రాంచ్‌లోకి మారడానికి.

  • git merge <name>: ఒక బ్రాంచ్‌లో చేసిన మార్పులను ప్రస్తుత బ్రాంచ్‌లోకి కలపడానికి.

  • git branch: మీ ప్రాజెక్ట్‌లో ప్రస్తుతం ఎన్ని బ్రాంచ్‌లు ఉన్నాయో చూడటానికి.

Git బ్రాంచింగ్‌లో మీరు పని చేసే క్రమాన్ని బట్టి (Workflow), అన్ని ముఖ్యమైన కమాండ్లను ఇక్కడ ఒక పద్ధతిలో వివరిస్తున్నాను:

1. బ్రాంచ్‌ల స్థితిని తెలుసుకోవడం (Viewing)

ఏదైనా చేసే ముందు, అసలు ఏ బ్రాంచ్‌లు ఉన్నాయో చూసుకోవాలి.

  • git branch: లోకల్ బ్రాంచ్‌ల లిస్ట్ చూపిస్తుంది. (మీరు ఉన్న బ్రాంచ్ పక్కన * ఉంటుంది).

  • git branch -v: ప్రతి బ్రాంచ్‌లో చివరగా చేసిన కమిట్ (Last commit) వివరాలను చూపిస్తుంది.

2. కొత్త బ్రాంచ్ సృష్టించడం మరియు మారడం (Creating & Switching)

పని ప్రారంభించేటప్పుడు వాడే కమాండ్స్ ఇవి.

  • git branch <name>: కొత్త బ్రాంచ్‌ని క్రియేట్ చేస్తుంది.

  • git switch <name>: ఒక బ్రాంచ్ నుండి ఇంకో బ్రాంచ్‌లోకి మారుస్తుంది.

  • git switch -c <name>: (ముఖ్యమైనది) కొత్త బ్రాంచ్‌ని సృష్టించి, వెంటనే అందులోకి మారుస్తుంది (ఇది git checkout -b కి సమానం).

3. పేరు మార్చడం (Renaming)

  • git branch -m <new-name>: ప్రస్తుతం మీరు ఉన్న బ్రాంచ్ పేరును మార్చడానికి.

4. మార్పులను కలపడం (Merging)

మీ కొత్త ఫీచర్ పని పూర్తయిన తర్వాత, దాన్ని మెయిన్ కోడ్‌లో కలపడానికి.

  • git merge <branch-name>: వేరే బ్రాంచ్‌లోని మార్పులను మీరు ప్రస్తుతం ఉన్న బ్రాంచ్‌లోకి తెస్తుంది.

5. డిలీట్ చేయడం (Deleting)

పని పూర్తయి మెర్జ్ చేసిన తర్వాత, అనవసరమైన బ్రాంచ్‌లను తొలగించడానికి.

  • git branch -d <name>: బ్రాంచ్‌ని డిలీట్ చేస్తుంది (ఒకవేళ అది మెర్జ్ అయి ఉంటేనే).

  • git branch -D <name>: మెర్జ్ అవ్వకపోయినా సరే, బలవంతంగా డిలీట్ చేస్తుంది.

6. రిమోట్ సర్వర్‌తో (GitHub/GitLab) పని చేయడం

  • git push origin <name>: మీ లోకల్ బ్రాంచ్‌ని రిమోట్ రిపోజిటరీకి పంపుతుంది.

  • git push origin --delete <name>: రిమోట్ సర్వర్‌లో ఉన్న బ్రాంచ్‌ను డిలీట్ చేస్తుంది.


ఒకే టేబుల్‌లో పూర్తి సారాంశం:

క్రమం (Order)కమాండ్ (Command)వివరణ (Simple Explanation)
1. Viewgit branchఉన్న బ్రాంచ్‌ల లిస్ట్ చూడటానికి.
2. Create & Switchgit switch -c <name>కొత్త బ్రాంచ్ సృష్టించి అందులోకి వెళ్లడానికి.
3. Renamegit branch -m <new-name>బ్రాంచ్ పేరు మార్చడానికి.
4. Check Outgit switch <name>వేరే బ్రాంచ్‌కి మారడానికి.
5. Combinegit merge <name>కోడ్‌ని కలపడానికి.
6. Clean upgit branch -d <name>పని అయిపోయిన బ్రాంచ్‌ను తీసేయడానికి.
7. Syncgit push origin <name>సర్వర్‌లోకి అప్‌లోడ్ చేయడానికి.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.