Terminal Git Github Manual 2
Terminal Git Github Manual 2
md 8/1/2023
PART 2: Git
Table of Contents
1. Introduction to Version Control
What is version control?
Why use version control?
Types of version control systems
2. Git Fundamentals
Installing Git and configuration
Basic Git commands
Git workflow
1/7
notes.md 8/1/2023
2/7
notes.md 8/1/2023
3/7
notes.md 8/1/2023
4/7
notes.md 8/1/2023
2. Git Fundamentals
Installing Git
To use Git, you need to install it on your local machine. Here's how you can install Git:
Windows: Download the Git installer from the official Git website (https://git-scm.com/) and run the
executable file. Follow the installation wizard, and Git will be installed on your system.
macOS: Git usually comes pre-installed on macOS. If it's not already installed or you want to get the
latest version, you can use Homebrew (brew install git) or download the installer from the
official Git website.
Linux: On most Linux distributions, you can install Git using the package manager. For example, on
Ubuntu, you can use apt-get with the command sudo apt-get install git.
Git Configuration
Configuring Git for the first time after installation involves setting up your identity and some basic settings.
Here are the steps to configure Git:
1. Set Your Username and Email:
Open a terminal or command prompt, and run the following commands to set your name and email:
5/7
notes.md 8/1/2023
Replace "Your Name" with your actual name and "[email protected]" with your email address. The -
-global flag ensures that these settings apply globally to all repositories on your machine.
3. Check Configuration:
You can check your Git configuration by running:
This will display a list of all the settings that Git currently has, including your name, email, and other
configurations.
4. Set Default Branch Name (Optional, Git 2.28+):
Starting from Git version 2.28, you can configure the default branch name. If you want to change the default
branch name from "master" to something else (e.g., "main"), use the following command:
6/7
notes.md 8/1/2023
git commit -m "commit message": Commits the staged changes with a brief description.
git status: Shows the current status of your working directory, including changes and staged files.
git log: Displays the commit history, showing the author, date, and commit message for each
commit.
git push: Pushes your local commits to a remote repository.
git pull: Pulls the latest changes from a remote repository and merges them into your local
branch.
git branch: Lists all branches in the repository.
git merge <branch_name>: Merges the changes from the specified branch into the current
branch.
3. Git Workflow:
The typical Git workflow involves the following steps:
Initializing a Repository: Create a new repository or clone an existing one to your local machine
using git init or git clone.
Working on the Code: Modify the files in your working directory according to the changes you want
to make.
Staging Changes: Use git add to stage the changes you want to include in the next commit.
Committing Changes: Create a new commit using git commit -m "commit message" to save
the staged changes with a descriptive message.
Pushing Changes: If you're working with a remote repository, use git push to send your commits
to the remote server.
Pulling Changes: Before making new changes, use git pull to fetch and merge the latest changes
from the remote repository into your local branch.
Branching and Merging: Use branches (git branch) to work on new features or bug fixes without
affecting the main codebase. Merge the changes into the main branch using git merge.
Review and Collaboration: Git allows code review and collaboration by sharing repositories among
team members. Changes can be reviewed using pull requests and discussions on the code.
7/7