Everybody needs to learn GIT! Learning GIT is not only a great skill to have but it is also a necessary one. Precisely because software development is characteristically more like a journey you take with your friends than a destination you reach individually. What do I mean by that? It is a process that requires constant refinement & correction as you work in collaboration with other developers. GIT is an application which helps to facilitate this process of refinement & correction with version control.i.e creating, cloning, making & reversing changes and integrating those versions of changes into the code base. The code base or source code is saved on Github so that it can be accessed by developers who want to contribute.
I will try to explain the basics of GIT to consolidate my knowledge & help you break it down with my simple & straight forward explanation.
Before we start, follow these instructions on this website here to install GIT if you've not already done so.
I am going to assume that you have a Github account and you're familiar with it.
In addition I am going to be using the command line on MacBook to create directories/folders to start a project to be used as an example
Okay with the above taken care of, let's start with the basics of GIT using an example.
GIT for starting your own individual project
And then it will open in the Vs Code like this.
Now let's create a remote repository that will save all the changes made on your local repository.
Add and connect the remote repository to the local
repository by following the instruction below.
- Initialize the repo using 👉 git init
- Create new files or make changes to your code base.
- And then use 👉 git add . to add the changes.
- Check if the changes have been tracked using 👉 git status.
- If they have been tracked it will let you know as follow.👇If not it will show the files or changes not tracked in red.
Then commit the changes using 👉 git commit -m "changes made description"Then add & connect the remote repo to the local repo as follows. 👉 git remote add origin i.eOnce you have established the connection between the remote & local repo, then you can push the changes made on the local repo to be merged into the master or main remote repo.i.eYou can double check if your commit has been pushed to the remote repo you created for your individual project for the first time by refreshing the page. You should be able to see something like this 👇
To create a new branch you use 👉 git branch - branch name.i.e
And then to switch to the new branch you created,
you use 👉 git checkout - branch name. i.e It will then show you have switched from the master branch to the new newFeature branch.
You can accomplish both git command lines above with just one combined git line as follow 👉 git checkout -b newFeature
Here I created and switched to another branch named anotherFeature using the combined git line 👉 git checkout -b anotherFeature. You can check the number of branches using 👉 git branch --list and it will show you list of branches as follows.The one highlighted in green is the branch you're currently on.
You can then work on your feature and commit the change👇And push the changes as follows to remote repo👇And you can check you've done it right by going to the remote master/main repo on Github.If you have've done it right you should see a message similar to the above.
To create a pull request, first switch to master/main branch. Then pull request from the branch you worked on or made changes using - git pull origin branch name as follows 👇 Pull requests can also be done manually on the Github page. That's where I usually do it when I am working in group. Often times it has to be reviewed by another group member before it gets merged into the master/main branch.
The explanation so far is enough to get you going when working by yourself on an individual project. In part two of these series, I will talk about how to clone & start from an already made up code base.
Thank you🙏🏾👨🏾💻 for reading my blog so far. Please follow my blog or follow me on twitter @wolde_ai to get more of these series on GIT. I welcome any kind of criticism as it is part of the learning process.✌🏾🤓