Skip to main content

Command Palette

Search for a command to run...

Push & Pull Perspectives - Git Basics.

Published
•3 min read•View as Markdown

Chapter 1: What is Git?

Git is a distributed version control system designed to track changes in files and coordinate work among multiple contributors. Unlike centralized systems, Git allows each user to have a complete copy of the repository, enabling collaboration without relying on a central server.

Chapter 2: Setting Up Git

Before you can start using Git, you'll need to install it on your computer. Fortunately, Git is available for all major operating systems, including Windows, macOS, and Linux. Once installed, you'll need to configure Git with your name and email address using the following commands:

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

Chapter 3: Getting Started with Git

To start using Git in a project, you first need to initialize a Git repository in the project directory. This can be done using the git init command:

cd my_project
git init

Once initialized, Git will start tracking changes in your project files.

Chapter 4: Tracking Changes

Git tracks changes in your project files by comparing the current state of the files to their previous state. You can check the status of your files using the git status command:

git status

To stage changes for commit, you use the git add command:

git add file1.txt file2.txt

Finally, you commit your changes to the repository using the git commit command:

git commit -m "Add new feature"

This creates a new commit with a message describing the changes you've made.

Chapter 5: Exploring History

Git maintains a complete history of all commits in your project. You can view the commit history using the git log command:

git log

This will display a list of commits, including the commit hash, author, date, and commit message. You can navigate through the commit history using various options and filters provided by git log.

Chapter 6: Branching and Merging

A branch in Git is a lightweight movable pointer to a commit. You can create a new branch using the git branch command:

git branch new_feature

To switch to a different branch, you use the git checkout command:

git checkout new_feature

Once you've completed your work on a branch, you can merge it back into the main branch (usually master) using the git merge command:

git checkout master
git merge new_feature

Chapter 7: Collaborating with Git

Git enables seamless collaboration among team members by allowing them to work on different branches and merge their changes together. To collaborate with others using Git, you'll typically use a remote repository hosting service like GitHub or GitLab. You can clone an existing repository to your local machine using the git clone command:

git clone https://github.com/user/repository.git

Once you've made changes to your local repository, you can push them to the remote repository using the git push command:

git push origin master

Similarly, you can pull changes from the remote repository to your local repository using the git pull command:

git pull origin master

Chapter 8: Resolving Conflicts

Occasionally, when merging branches or pulling changes from a remote repository, you may encounter merge conflicts. These occur when Git is unable to automatically resolve differences between conflicting changes. To resolve merge conflicts, you'll need to manually edit the affected files to resolve the conflicting changes, then commit the changes to complete the merge.

See you again...