Git is a widely-used, open-source version control system that helps you track changes in your code, collaborate with others, and manage different versions of your project. Here’s a simple overview of the basic Git concepts and commands.
Key Concepts
Repository (repo):
A directory that contains your project and all the Git history for it.Commit:
A snapshot of changes made to the files in your project.Branch:
A separate line of development. The default branch is usually calledmain
ormaster
.Remote:
A copy of the repository stored on a server (e.g., GitHub, GitLab, Bitbucket).Clone:
A copy of a remote repository on your local machine.Staging Area (Index):
A place where you prepare changes before committing.
Common Git Commands
1. Initialize a Repository
Start a new Git repository in your project directory.
2. Check Repository Status
Shows the status of your working directory and staged changes.
3. Add Changes to Staging Area
Add files to the staging area before committing.
4. Commit Changes
Save your changes with a message describing the changes.
5. View Commit History
Show a log of commits
6. Create a New Branch
Create and switch to a new branch.
7. Merge a Branch
Merge changes from another branch into the current branch.
8. Clone a Remote Repository
Copy a remote repository to your local machine.
9. Push Changes to Remote Repository
Upload your local commits to a remote repository.
10. Pull Changes from Remote Repository
Fetch and merge changes from the remote repository.
11. Check Differences
Show changes that haven’t been staged or committed.
Simple Workflow Example
Initialize a Repository
Add Files and Commit
Create and Switch to a New Branch
Make Changes and Commit
Merge the Branch Back to Main
Push Changes to Remote Repository
Comments
Post a Comment