Welcome to the Git Essential repository! Here, we’ll explore the foundational concepts and key commands of Git, one of the most popular and powerful tools for version control.
- What is Git?
- What is Git used for?
- How to Use Git Simply
- Essential Command Guide
- About the Author
- License
Git is a distributed version control system created in 2005 by Linus Torvalds, the same developer behind the Linux kernel. The need for a secure, fast, and reliable version control system arose during the development of Linux itself. Git quickly gained prominence for its innovative features and the security it offers for handling change history.
Git allows developers to track all changes made to a project’s code, making it easier to collaborate and integrate changes from different contributors. In addition to storing and managing different versions, Git provides tools to:
- Create independent branches for new features
- Merge changes across branches
- Store snapshots of code progress (commits)
- Revert changes and access the full project history
This versatility is essential for collaborative development and efficient code management.
Getting started with Git can seem complex, but a few essential commands cover most needs:
-
Install Git: Git Downloads
-
Configure Git (username and email):
git config --global user.name "Your Name" git config --global user.email "[email protected]"
-
git init
: Initializes a new Git repository in the current directory. -
git remote add origin <repository-url>
: Adds a remote repository to the local one with the name "origin." -
git branch -M main
: Renames the current branch to "main." The-M
option forces the rename, moving the branch if necessary.
-
git add .
: Adds all files and changes in the current directory to the staging area, preparing them for the commit. -
git commit -m "commit message"
: Records the changes in the staging area with a descriptive message about what was modified. -
git commit --amend -m "rewritten_message"
: Changes the message of the last commit. After using this command, sync with the remote usinggit push --force-with-lease
.
-
git clone <repository-url>
: Clones a remote repository from GitHub to your local environment. -
git push -u origin main
: Sends the commits on the "main" branch to the "origin" remote repository, setting "main" as the default branch for future push and pull commands. The-u
option sets the upstream to simplify future push and pull commands. -
git pull origin main
: Updates the local "main" branch with changes from the "origin" remote repository, combininggit fetch
andgit merge
.
-
git fetch
: Fetches updates from the remote repository without merging them into the current branch, updating remote references. -
git merge <branch-name>
: Combines the changes from the specified branch into the current branch. For example, to merge a feature branch intomain
:git merge feature-branch
This command applies the changes from the
feature-branch
tomain
, maintaining a clear history of commits. It’s particularly useful in workflows like the Feature Branch Workflow. -
git revert <commit-hash>
: Creates a new commit that undoes the changes made by the specified commit, preserving the history. Useful for safely reversing changes without rewriting the history. -
git reset --hard <commit-hash>
: Resets the repository to the state of the specified commit, deleting all changes made after that commit. Ideal for local use. To sync remotely, follow up withgit push --force-with-lease
. -
git cherry-pick <commit-hash>
: Used to retrieve a specific commit. Example: Suppose you have two branches ("main" and "develop") and want to pick just one commit from "develop";cherry-pick
allows you to do this. -
git push --force-with-lease
: A safer way to force-push local changes to the remote repository. It checks that no changes have been made by other collaborators, avoiding accidental overwrites.
This repository was created and is maintained by Ciro Cesar Maciel. I am a Software Engineer passionate about creating efficient and well-documented solutions. I am always looking for new tools and practices that can simplify and improve the development workflow.
In addition to this project, I have been working on other interesting projects related to automation, Artificial Intelligence (AI), browser extensions, and more. I am also beginning to teach what is necessary to learn Artificial Intelligence (AI), helping others to get started on their AI journey.
If you are interested in Software Development, Data Science, AI, or other tech topics, feel free to explore my GitHub profile and connect with me.
- GitHub: ciro-maciel
- LinkedIn: Ciro Cesar Maciel
- Website: ciro-maciel
I am always open to new collaborations and projects. If you have an interesting idea or just want to exchange thoughts about development, don't hesitate to reach out!
This project is licensed under the MIT License - see the LICENSE file for details.