25 Tweets 9 reads Dec 25, 2022
Git is undoubtedly you'll end up using if you're working in a technical position.
You could find a lot of value in this 3 minute read thread. ๐Ÿงต
Git is a version control system that allows developers to track changes to their codebase over time.
It allows multiple people to work on a project simultaneously, while also keeping a record of every change made.
With Git, developers can create a repository (or "repo") to store their code. They can then make changes to the code and "commit" those changes to the repo, along with a message explaining the changes.
Each commit creates a new "version" of the code, and Git stores a complete history of all the commits made to the repo. This allows developers to easily revert back to previous versions if necessary.
Git also allows developers to create branches, which are separate versions of the code that can be worked on concurrently.
Once the changes on a branch are ready, they can be "merged" back into the main branch (also known as the "master" branch).
Here's how Git operates:
When a developer wants to start working on a new feature or fix a bug, they create a new branch in the Git repository. This allows them to work on their changes without affecting the main codebase.
As the developer makes changes to the code, they can commit those changes to their branch.
Each commit is like a snapshot of the code at a specific point in time, and it includes a message describing the changes made in that commit.
When the developer is ready to merge their changes into the master branch, they create a "pull request." This is a request to merge their branch into the master branch.
Other members of the team can review the pull request and discuss any changes or issues with the code. Once the team is satisfied with the changes, they can approve the pull request and merge the changes into the master branch.
Let's discuss 10 widely used Git commands:
1. `git init`
Initialize a new Git repository.
This creates a new subdirectory named ".git" in the current directory, where Git stores all the metadata for the repository.
2. `git clone`
Clone an existing repository.
This creates a local copy of the repository, including all of its history and branches.
`git clone <repo-link>`
3. `git add`
Stage changes for the next commit.
This adds the specified file(s) to the staging area, where they will be included in the next commit.
`git add file1.txt file2.txt`
4. `git commit`
Create a new commit.
This records the staged changes and any additional changes made since the last commit, along with a commit message describing the changes.
`git commit -m "Add new feature"`
5. `git push`
Push commits to a remote repository.
This sends the local commits to the specified remote repository, updating the branch on the remote with the new commits.
`git push origin main`
6. `git pull`
Fetch and merge changes from a remote repository.
This retrieves the latest commits from the specified remote repository and merges them into the current branch.
`git pull origin main`
7. `git branch`
List, create, or delete branches.
This command can be used to list the available branches in a repository, create a new branch, or delete an existing branch.
`git branch new-branch`
8. `git checkout`
Switch to a different branch.
This command allows you to switch to a different branch in the repository and make it the current working branch.
`git checkout main`
9. `git merge`
Merge one branch into another.
This command combines the changes from one branch into another branch, creating a new commit that reflects the merged changes.
`git merge new-branch`
10. `git status`
Show the status of the repository.
This command displays the current branch, any staged or unstaged changes, and any untracked files.
`git status`
Thanks for reading! Follow me if you like this thread. ๐Ÿ˜

Loading suggestions...