Git¶
π 𧬠Overview¶
Git is a distributed version control system that helps developers track changes in their codebase, collaborate efficiently, and manage source code history. It's an essential tool for modern software development and DevOps workflows.
π‘ Key Features¶
- Tracks and manages changes across projects
- Supports branching, merging, and rollbacks
- Enables collaborative development via platforms like GitHub and GitLab
- Works both locally and with remote repositories
- Integrates with most CI/CD systems
π Use Cases¶
Hereβs how I personally use Git in my workflow:
- Local version control for all coding and documentation projects
- Used in conjunction with GitLab and GitHub for remote backups and collaboration
- Powers CI/CD deployments for websites and documentation
- Git hooks for automation (e.g., pre-commit linting)
βοΈ Setup & Configuration¶
Install Git and configure your identity:
# Install Git (Debian/Ubuntu)
sudo apt install git
# Configure username and email
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check your setup with:
git --version
git config --list
π Resources¶
π§ Notes & Tips¶
- Always write meaningful commit messages
- Use
.gitignore
to avoid committing unwanted files - Use interactive rebase (
git rebase -i
) for clean history - If you mess up:
git reflog
is your friend - Lazygit: An intuitive terminal UI for Git. See diffs, stage/unstage, stash, rebase β all in one place.
π Mirroring GitLab β GitHub¶
I use a GitLab-to-GitHub mirror to keep my repositories in sync.
π₯ Video Guide from ShowMeYourCode!:
Dealing with Git Merge Conflicts¶
-
Stash changes (optional):
Temporarily save uncommitted changes before merging:
git stash -
Merge the feature branch:
git merge <branch-name>
-
Check status and logs:
git status
git log --merge --oneline
-
Identify conflict markers in files:
Look for markers like:
<<<<<<< HEAD [your changes] [incoming changes] >>>>>> feature-branch
-
Resolve conflicts manually:
Edit the files to keep or combine changes, then remove the markers. -
Add and commit resolved files:
git add <filename>
git commit
-
Abort the merge (if necessary):
To cancel the merge and return to the pre-merge state:
git merge --abort
You can follow this guide or others for more information: