🐙 Git Basics 🐙
Git is the ultimate tool for tracking changes made to files over time. Revert to older versions? Sure thing!
Here's a simple thread to understand the base of #Git and #Github#beginnerfriendly#vscode
The user can control which version of the file to chose from.
This is powerful bcuz even if mistakes are made in a newer version, user can just revert back to an older version.
This is why Git is called a Version Control System (VCS).
Here's an overview of the workflow of Git:
The place or location where Git is enabled is known as the Git Repository.
To initialize a folder as Git Repo, go the folder location on a terminal and type 'git init'.
Now you have told Git about the location, next is the files you want git to track.
To chose specific files to track, type "git add [filename]" to the terminal.
Cool, now you are tracking the changes to the file. You can type "git add -A" to track all files in the folder at once.
Once your done with a feature or want to save a version of the files, you need to type "git commit -m [message]" in the terminal
This will take a snapshot of the whole file system(the folder) and the message you write should describe the changes you made in an clear manner.
Remember, when your working as a team, the message has to be clear from your side in a way your team understands.
Note that all of the mentioned events are done locally on your machine. You'll most likely have a remote repository on a website like Github or Gitlab or Bitbucket.
To push your changes to the remote repo, you'll first need to connect your local repo with the remote repo.
You can create the remote repo easily using the website like Github (its self explanatory).
Once done, you can use the command `git remote add origin [repo_link]` with the link of your remote repository to connect the local and remote repos.
I have made a CheatSheet for Git commands, here's the link:
gist.github.com/tyrovirtuosso/7210210a4f04a087fd3d65b6019cdbf2
Once you have connected, you can pull the contents of the remote repo to the local by typing 'git pull' command. Note, there are several variations of git pull, which I have highlighted in the cheatsheet.
Similarly, you can push changes from the local repo to the remote repo using 'git push'
If others have made changes to the remote repository, you can download those changes to your local repository by running the "git pull" command.
If you're using #vscode, there is an official Github extension which makes the connection seamless!
Git Branches is the one of the most vital feature that makes Git what it is! You can consider it as a secondary copy of your repository that allows you to work on new features or changes without affecting the original code.
For example, let's say you're working on a project with several other people, and you want to add a new feature to the code. You can create a new branch in the GitHub repository specifically for working on this feature.
This branch will contain a copy of the entire codebase, butyou can make changes to it without affecting the main branch.
Once you've made the changes you want to make, you can merge the branch back into the main branch. This allows you to incorporate your changes into the main codebase, while still keeping the original code intact.
The commands are for branches are given in the cheatsheet.
Awesome, now that you have a fundamental base of Git, we'll get into various mental models that will help with your workflow!
But thats for another thread! Let me know if this was simple enough and where I could improve.
Like and Follow for updates!