Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Git Command Reference

This document provides a comprehensive reference for essential Git commands, including cloning a repository, navigating directories, checking repository status, staging and committing changes, pushing to a remote repository, and viewing commit history. It explains the purpose of each command, provides examples, and outlines important concepts such as branches, the working directory, and the staging area. A workflow summary is also included to guide users through the typical Git process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Git Command Reference

This document provides a comprehensive reference for essential Git commands, including cloning a repository, navigating directories, checking repository status, staging and committing changes, pushing to a remote repository, and viewing commit history. It explains the purpose of each command, provides examples, and outlines important concepts such as branches, the working directory, and the staging area. A workflow summary is also included to guide users through the typical Git process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Git Command Reference:

1. Cloning a Repository
●​ Purpose: To create a local copy of a remote repository (e.g., from GitHub).
●​ Command:​
git clone <repository_url>​

●​ Example:​
git clone https://github.com/yourusername/your-repo.git​

2. Navigating to Your Repository


●​ Purpose: To change the current directory in your terminal to your Git repository's
folder.
●​ Command:​
cd <directory_path>​

●​ Example:​
cd Desktop/my-project​

3. Checking the Repository Status


●​ Purpose: To display the state of your working directory and staging area. It shows
modified files, staged files, and untracked files.
●​ Command:​
git status​

●​ Example Output:​
On branch main​
Your branch is up to date with 'origin/main'.​
Changes not staged for commit:​
(use "git add <file>..." to update what will be committed)​
(use "git restore <file>..." to discard changes in working directory)​
modified: TimurDesign/agent.sv​
no changes added to commit (use "git add" and/or "git commit -a")​
4. Staging Changes
●​ Purpose: To add changes to the staging area (index), preparing them for the next
commit.
●​ Command:
○​ Stage a specific file:​
git add <filename>​

○​ Stage all changed files:​


git add .​

●​ Examples:​
git add TimurDesign/agent.sv​
git add README.md​
git add .​

5. Committing Changes
●​ Purpose: To create a snapshot of the staged changes in the local repository's
history.
●​ Command:​
git commit -m "Commit message describing the changes"​

●​ Example:​
git commit -m "Added new feature to agent.sv"​
git commit -m "Fixed bug in user authentication"​

6. Pushing Changes
●​ Purpose: To upload local commits to the remote repository (e.g., GitHub).
●​ Command:​
git push <remote_name> <branch_name>​

●​ Example:​
git push origin main​

7. Viewing Commit History


●​ Purpose: To display the history of commits in the repository.
●​ Command:​
git log​

●​ Examples:
○​ Basic log:​
git log​

○​ One-line log with graph and decorations:​


git log --oneline --graph --decorate​

○​ Show patch for each commit​


git log -p​

8. Understanding Branches
●​ Purpose: To create parallel versions of your project for feature development, bug
fixes, and experimentation.
●​ Analogy: Think of branches as separate timelines or "universes" of your project.
●​ Main Branch: The primary branch (usually main), representing the stable version
of your code.
●​ Feature Branch: A branch created to develop a specific feature.
●​ Bug Fix Branch: A branch created to fix a bug.
●​ Command to create a branch:​
git branch <new_branch_name>​

●​ Command to switch to a branch:​


bash git checkout <branch_name>
●​ Example:​
git branch feature-x​
git checkout feature-x​

9. Viewing Staging Area


●​ Command:​
bash git status
●​ The "Changes to be committed:" section of the output shows you the files that
are currently in the staging area.
Important Concepts
●​ Working Directory: The directory on your computer where your project files are
located.
●​ Staging Area (Index): A temporary area where you prepare changes for a
commit.
●​ Local Repository: The Git repository on your computer.
●​ Remote Repository: The Git repository hosted on a server (e.g., GitHub).
●​ Commit: A snapshot of your changes at a specific point in time.
●​ Branch: A separate line of development. The main branch is typically called main.
Workflow Summary
1.​ Clone: git clone (if starting with an existing repository)
2.​ Navigate: cd (to your repository)
3.​ Make Changes: Edit files in your working directory.
4.​ Check Status: git status (to see changes)
5.​ Stage Changes: git add (to prepare changes)
6.​ Commit Changes: git commit (to save a snapshot)
7.​ Push Changes: git push (to share with remote)
8.​ Check History: git log (to see commit history)

You might also like