Quick plug before we get started: this post was original published in my new blog site, check it out if you want to read more like this! I'll be posting a new blog every Monday!
Now let's Git Started!
Git is an absolute MUST, that every developer should know how to use. It makes you a lot more productive and of course has version control, which can save you a ton of time and other problems. Actually getting started and understanding Git for the first time might not be too easy, so today I'll just be showing you some basic commands.
Table Of Contents
Repository Basics
A repository is a project, using the terminal you can create a repository by first going into the directory in which you want to start the repository in (using cd <directory>
) and then typing git init <project-name>
Or to work in a copy of an already-made repository
git clone <url/to/repository>
To work in a copy of an already-made local repository:
git clone <path/to/repository>
Staging Files
The files that you stage are essentially the files that you're going to want to be in the commit (which we will talk about soon). You can stage a file by using git add <file-name>
or use git add --all
if you want to add all files to the stage. But I would add all the files to the stage manually to avoid anything bad.
Committing in Git
What is a commit?
Ok so if you are new to Git then this might be a new term for you. A commit is usually made when you change one or multiple files (or create/delete them too). Each commit is assigned to a unique ID to track the contribution made by that commit and the time in which the commit was made.
How to commit?
If you are in the terminal the command to commit is git commit -m '<message>'
. As you can see each commit requires a message this should be short but still understandable.
Branches
Branches allow you to work with a different version of a repository at one time, every repository will have the main repository by default, which is what is usually the "definitive branch" or where the main production and final code will be. This makes it easier for multiple people to easily work on code. Once a branch is ready with enough commits, it is merged and then a pull request is made so it gets added to the main
branch.
Pull Requests
What are pull requests?
Pull requests are made when the commits are ready to be merged from one branch to another branch. There is usually one developer who verifies and reviews that the code is ready before it is pulled, which makes it so that only good code (non-malicious or bug-free code) gets into a branch.
Conclusion
You might start to notice how Git can be useful (but maybe a little overwhelmed too), you can check out their very good docs if you'd like to go a little more in-depth into this topic.
I appreciate you spending your time reading this post, if you'd like to read more here you go:
Top comments (0)