Revisiting Git fundamentals and experiments

My Git learnings & experiments Hey LinkedIn — I spent time today revisiting Git fundamentals and ran a few hands-on experiments. Here’s the cleaned-up, practical summary of what I learned and why it matters 🔧 Repo setup — the basic flow Commands I ran and why: # create a repo locally cd <your-directory> git init # stage everything git add . # rename (or set) the main branch git branch -M main  # renames current branch to "main" (or creates it if not present) # create first commit git commit -m "first commit on branch main" # push to remote and set upstream git push -u origin main Notes: main is a convention (a modern replacement for master) — you can name the branch anything, but main is commonly used for clarity and inclusiveness. git push -u origin main sets the upstream so future git push works without specifying branch. 🧠 Staging, commits, and branch context — key clarifications A few important details I confirmed by practicing: git add stages changes into the index (the staging area) which is repository-wide — not “attached to a branch” in a direct sense. Commits are created on whichever branch your HEAD currently points to. So: If you are on feature and run git commit, the commit belongs to feature. Pushing what ends up on the remote branch depends on which ref you push. Common gotcha I clarified: git push origin main attempts to push your local branch named main to origin/main. If you want to push the current branch to the remote main branch, you must explicitly push your current HEAD to that ref, e.g.: # push current branch to remote branch named main git push origin HEAD:main That command updates origin/main with the commits from your current branch (HEAD). This explains why changes can appear on main even when you were “on” another branch — because the push target was explicitly set to main. Takeaway: Always double-check git status, git branch, and the exact git push refspec you use before pushing to protected branches like main. #Git #GitCommands #VersionControl #DevOps #SoftwareEngineering #CodingJourney #LearningInPublic #100DaysOfCode #TechLearning #ProgrammersLife #DeveloperTools #SoftwareDevelopment #CodeNewbie #EngineeringExcellence #TechCommunity

  • chart, line chart

To view or add a comment, sign in

Explore content categories