Cosmic Guide to Biohacking Sleep · CodeAmber

How to Use Version Control with Git: From Init to Merge Conflict Resolution

How to Use Version Control with Git: From Init to Merge Conflict Resolution

Master the essential Git workflow to track changes, collaborate with other developers, and maintain a stable codebase through structured versioning.

What You'll Need

Steps

Step 1: Initialize the Repository

Navigate to your project folder in the terminal and run 'git init'. This creates a hidden .git directory that allows Git to begin tracking every change made to your files.

Step 2: Stage and Commit Changes

Use 'git add .' to move modified files into the staging area. Follow this with 'git commit -m "your descriptive message"' to create a permanent snapshot of the current state of your code.

Step 3: Connect to a Remote Server

Create a new repository on your hosting platform and link it using 'git remote add origin [URL]'. Use 'git push -u origin main' to upload your local history to the cloud for the first time.

Step 4: Implement Feature Branching

Avoid working directly on the main branch by creating a feature branch with 'git checkout -b feature-name'. This isolates new development and prevents unstable code from breaking the production environment.

Step 5: Sync with Remote Changes

Before merging, run 'git pull origin main' to integrate the latest updates from your team. This ensures your local environment is up-to-date and helps identify potential conflicts early.

Step 6: Merge Branches

Switch back to the main branch using 'git checkout main' and execute 'git merge feature-name'. This incorporates the completed feature into the primary codebase.

Step 7: Resolve Merge Conflicts

If Git cannot automatically merge changes, open the conflicted files and manually choose which code to keep. Once resolved, stage the files with 'git add' and finalize the process with a commit.

Expert Tips

See also

Original resource: Visit the source site