Git: Online Co-Working Space for Developer Team

Rabialco Argana
6 min readMar 18, 2021
Image Source from Unsplash

Hmmm, what is Git?

Git is an Open Source Distributed Version Control System that has a remote repository that is stored in a server and a local repository that is stored in the computer of each developer.

What is used for?

Git is primarily used for source code management in software development teams or individuals. Another usability of git that it can be used to keep track of changes in any set of files and do collaborative work between people. Basically, git is a version control system that allows you to work together with other developers and all of you will be using the same codebase.

How to use Git?

There are three basic way to set up and start using Git

  • Create a new repository

The aim of this method is to create a new repository when you don't have any existing folder to upload and make a new one.

The First Step, clone your online repository to your local file. This step is used to make a local folder that has a connection to your git online repository folder.

git clone https://gitlab.com/rabialco/testing-gitlab.git
Example of git clone from repo folder

After the online repository created in your local file, go inside your folder.

cd testing-gitlab

If you want your local repository visible in your git online repository, make any new file that you want to upload to git.

touch <file-name>

After the file created, now it’s time to submit your file changes in your folder to the staging area.

# Add certain file to staging area
git add <file-name>

# Add all file to staging area in the folder
git add -A
Example of git add .

Now it’s time to commit your work from the staging stage. In this process, you must specify your commit message so if you want to track your commit history, you know what changes are done in that commit.

git commit -m "<commit-message>"
Example of git commit

Lastly, you must push your commits to your git online repository after committing your work. The purpose of this step is to upload your file so it can be accessed on your git online repository.

git push origin master

2. Push an existing folder

The aim of this method is to push your existing local folder to your git online repository.

Firstly go inside your existing folder that you want to upload to your git online repository

cd existing_folder

When you’re already inside your folder, you must initialize the folder to be git type repository so it will be eligible to be upload to the git online repository

git init

Wow! Great job, now you’re ready to connect your local folder to your designated git online repository

git remote add origin https://gitlab.com/rabialco/testing-gitlab.git

After connecting your local folder to your git online repository, it’s time to submit all your file changes in your folder to the staging area.

git add .

Yeah, like the last process you must commit your work with a meaningful message, so if you want to track your commit history, you know what changes are done in that commit.

git commit -m "<commit-message>"

Lastly, (like the last process also) you must push your commits to your git online repository after committing your work. The purpose of this step is to upload your file so it can be accessed on your git online repository.

git push -u origin master
Example of push and existing folder (push, remote)

3. Push an existing Git repository

The aim of this method is to push an existing local git repository to your new git online repository.

The first thing you want to do is go inside your existing local git repository.

cd existing_repo

After inside the local git repository, because it has a different origin of the git online repository you must change your remote name

git remote rename origin old-origin

Great! the remote name already changes, now you must specify your origin to the new git online repository and connect it.

git remote add origin https://gitlab.com/rabialco/testing-gitlab.git

Lastly, (like always) you must push your commits to your git online repository after committing your work. The purpose of this step is to upload your file so it can be accessed on your git online repository.

git push -u origin --all
git push -u origin --tags

After the setup…. [Branching, Pull, Merging, Rebase, Revert, Stash]

  • Branching

The branch is an independent custom workspace or a working directory that you can put your work so it can’t be disturbed by another.

How to create a branch?

This is how you create your new branch with a certain name for your workspace.

git checkout -b <branch-name>

Or if you want to change your current branch to another branch.

git checkout <branch-name>

What did I do if I don’t know my branch name list? No Problem! You can check your branch name list by doing this command.

git branch
Example of git checkout
  • Pulling

This method is used when you want to update your local branch if there are changes to your collaborative git online repository.

git pull origin <branch-destination>
Example of git pull
  • Merging

This method is used when you want to combine your work with another person's work or the last changes in the main workspace.

git merge <designated-branch>git push <branch-destination>
Example of git merge
  • Rebase

This method is used when you want to integrate the commits from the next commit with the latest commit from one branch. Rebase compresses all the changes into a single one.

git rebase <branch-name>
Example of git rebase
  • Revert

This method is used when you want to undo your work changes to your designated history work commit. Revert will create a new commit from your designated previous commit.

# Find your commit hash from your undo commit target, and copy itgit log# Revert to your undo commit target with your designated commit hashgit revert <commit hash>
Example of git revert
  • Stash

This method is used when you want to save your work changes to your working copy so you can work on something else and when you need it you can re-apply them later.

# To save your workgit stash# To reapply the changes from history to your working copygit stash apply
Example of git stash

Difference between merge and rebase

This two instruction usually misunderstood by many people because have almost similar use. The similarities between these two are they both integrate changes from one branch into another. So what’s the difference between these two is that git rebase moves a feature branch into a master, Git Merge adds a new commit and preserving history.

Wow! Nice job finishing this article. Now you have mastered the basics git commands so you can start working with git ASAP!

Happy coding (?) / (!)

--

--