Basics of Git
What is Git?
Git is an open source distributed version control system which helps us keep track of our project by handling and tracking changes that we do to our projects.
(Git)ting started
You will need to download git’s client which will be different for each Operating System you are currently using.
Git’s download page.
Repository
To start working on your project you will need to create a new repository or use an existing one.
This is one of example of creating a repository in gitlab
you can also create a new repository using command
$ git init
Remote
Git remote is about remote repository that is shared between the user, you can add remote repository and can fetch the file from that repository
$ git remote add <name> <remoteURL>
$ git fetch <remote>
and also delete remote repository
git remote remove command
Clone
You can clone an existing repository to your local machine by typing simple command
$ git clone <repositoryURL>
Branch
Branches are where the project getting new or modified from the main project
master is the main branch and if you commit something on the branch the state will move forward tracking the record.
In our project the master branch is only for releasing the project while the staging branch is actually where all the feature are being added each time.
Checkout
You can easily switch between branch by using these command,
for switching to existing branch
$ git checkout branch_name for switching to a new non-existing branch
$ git checkout -b branch_name
Push
After making changes or adding files to your project you can push your local modification to the online repository by pushing them,
before you push the changes made you will be prompted to commit it first.
$ git commit -m "your commit message"$ git push
Stash
You can edit and save it to a stash if you don’t want to commit anything yet
by using this command
$ git stash
this stash will save your modified local files so you can work on other branches and you can simply apply the modified file after using this command if you want to commit the content of your stash.
$ git stash apply
Pull
If you want to get the latest version of your project you can pull the files from the server directly by pulling them by using this command
$ git pull
you can also pull specific branch on your repository by using this command
$ git pull origin <branch_name>
Merge
Branches commonly created so people can easily modify the current project simultaneously using the same version, after done with the changes or added feature people will push to respective branches.
If the newly added feature or changes is done and the project is running well you can merge the current branch to the main branch by Merging which needs some authorization from the admin of the project.
You can also merge branches directly using this git command
$ git merge
This merge command will create a final commit that squash all the commits in it.
Revert
Git also allows you to revert changes, However the changes reverted won’t be deleted but it will create a new state with previous state before changed.
$ git revert <commit>
You can also revert a merge by simply quoting the merging commit id that you have made.
Coldfix
A branch made to rollback a PBI branch.
This branch is applied when a Scrum Product Owner wants to revert the changes made before releasing the project.
Rebase
A rebase is commiting a squash of commits that have been made to a branch to the head of a certain branch.
$ git rebase <branch_name>
rebase work similarly like the merge but rebase commit doesn’t create another commit and recommit the target branch linearly as the last branch would.
Application of Git on our Logbook Project
Branches Usage
Here are how the branches work on our logbook project in our gitlab and its description.
- Master
This branch sole purpose is for release, the final project will be released here by the authorization of Project owner and lecturer - Staging
This branch is the main one for development, every new features will be added and merged to this branch - PBI
There will be many of these branches as it will be different for each feature created and will eventually be merged to the staging branch - Coldfix
This will be a branch solely for reverting a denied PBI by the Product Owner and which will eventually be merged back to the staging branch.
Code review in every Merge request
We haven’t had a code review as the project just started but on every merge we are having two or more people review each other’s merge request to ensure the quality of code.
This is all for my knowledge regarding basic of git
and how i apply it for our logbook project.
I hope this article is helpful
Thank you for reading :)