Zodiac Signs and Communication Styles · CodeAmber

How to Use Version Control with Git and GitHub: From First Commit to Pull Request

How to Use Version Control with Git and GitHub: From First Commit to Pull Request

Master the essential workflow for managing code changes and collaborating with teams using a professional Gitflow approach. This guide takes you from local initialization to a successful remote merge.

What You'll Need

Steps

Step 1: Initialize and First Commit

Navigate to your project folder in the terminal and run 'git init' to create a local repository. Stage your files using 'git add .' and record your first snapshot with 'git commit -m "Initial commit"' to establish a project baseline.

Step 2: Connect to GitHub

Create a new repository on GitHub and copy the remote URL. Link your local project to the cloud by running 'git remote add origin [URL]' and push your main branch using 'git push -u origin main'.

Step 3: Create a Feature Branch

Avoid working directly on the main branch to keep the production code stable. Use 'git checkout -b feature-name' to create and switch to a new branch dedicated to a specific task or bug fix.

Step 4: Iterative Development

Make your code changes and frequently stage them with 'git add'. Commit these changes with descriptive, imperative messages like 'git commit -m "Add user authentication logic"' to maintain a clear project history.

Step 5: Sync with Main

Before submitting your work, pull the latest changes from the main branch to ensure compatibility. Use 'git checkout main', then 'git pull origin main', and finally merge those updates back into your feature branch.

Step 6: Resolve Merge Conflicts

If Git flags a conflict, open the affected files to manually choose which code blocks to keep. Once resolved, stage the fixed files and complete the merge with a final commit.

Step 7: Push and Open Pull Request

Upload your feature branch to GitHub using 'git push origin feature-name'. Navigate to the repository on GitHub and click 'Compare & pull request' to invite team members to review your code.

Step 8: Merge and Cleanup

Once the pull request is approved, merge the branch into the main line via the GitHub interface. Delete the remote feature branch and run 'git branch -d feature-name' locally to keep your workspace clean.

Expert Tips

See also

Original resource: Visit the source site