The Power Of Git

Did you know that 80% of the project the git is involved?

When I work as desktop support as my first job. I will make a time to learn with the developers in our department.
My interest and willing to get back in programming made me curious of how they solve a certain problems.
It's cool and a great responsibility at the same time, as I saw the terminal they type in the commandline.
I understand that I should be flexible using tools.

And the one thing should I learn is git.

Git Workflow: One-time Setup

                        
    git clone https://github.com/repository-guide.git
    cd repo 
    git remove -v  # View remotes
                        
                    
If you're contributing in an Open-Source.
                        
    git clone https://github.com/your-username/repository.git
    cd repo 
    git remote add upstream https://github.com/original-owner/repository.git
                        
                    

Daily Start

                        
    # Team project
    git pull origin main 

    # Open-Source 
    git fetch upstream
    git checkout main
    git merge upstream/main
                        
                    

Create a Feature or BugFix Branch

                        
    git checkout -b feature/your-feature-branch
                        
                    

feature/ - for new features
fix/ - for bug fixes
hotfix/ - for critical fixes

Code & Track Changes

                    
    git status  # Check status, changes, and untracked files
    git add .   # Stage all changes
    git commit -m "Your commit message"  # Commit changes with a message
                    
                

NOTE: Commit messages should be clear
Use Imperative: "Add login feature"
Reference Issue Numbers: Fix #001: Handle empty states.

Push Branches

                    
    git push origin feature/your-feature-repo
                    
                

Create a Pull Request

1. Go to GitHub
2. Open a Pull Request from your branch to main or develop
3. Add a Description, Screenshots and linked issues.

Merge

                    
    git checkout main 
    git pull origin main
    git merge feature/your-feature-name
    git push origin main
                    
                

Optionally, you can delete the branch after merge.
Why?
This is the reason.

                    
    git branch -d feature/your-feature-name
    git push origin --delete feature/your-feature-name
                    
                

Cleanup

                    
    git fetch -p    # Remove deleted branches from remote
    git branch -a   # List all branches
                    
                

Undo or Roll Back (Safe Tools)

                    
    git log         # View Commit History
    git checkout   # View code from older commit 
    git revert      # Undo with a new commit
                    
                

Tip:

1. Use .gitignore to avoid committing unwanted files.
2. Make Atomic Commits: One logical change per commit.
3. Pull before pushing to avoid conflicts.
4. Resolve conflicts carefully, then git add and git commit

If ever I wanted to practice and check my git expertise.
I play this git website as my refresher