【Git, GitLab & GitHub】How to Make a Branch, Commit & Push

Arisa F
5 min readJul 1, 2019

--

Hi there, it’s me, Arisa, a freelance Frontend Developer.

To prevent forgetting, I make a note about how to make a branch, commit and push for mainly GitLab and GitHub.

(I know you see Bitbucket too …cuz I couldn’t find the best image… and I won’t mention this time Bitbucket, sorry!)

For those of you who are very new to Git, GitHub and GitLab, this note could be challenging.

But if you’re already familiar with terminal for Mac users, and have an environment that you’re ready to command with Git but just lost with branch, commit, push etc, this place is something for you.

Always happy to get advice if you know a better way to command!

Alright, let’s get start (:

Things to use this time: GitLab & GitHub

This time, I wanna leave a note for using GitLab and GitHub.

Actually, these names are already super similar.

Honestly, I misunderstood when someone asked me whether I have an account from GitLab as an account for GitHub…

This happens because I didn’t know at that time plus, no account for GitLab.

Anyway, the things I’ll be noting are very similar and both are based on Git.

Then, what’s the difference?

There is a few difference you can take a quick look.

What’s the difference between GitLab & GitHub?

If I describe super short for both difference for basics, GitHub allows you public projects for free and GiLab offers you private projects for free.

And more likely, GitLab is written in Ruby.

Means, open source project could be enough with GitHub.

Also, to show as part of your portfolio for engineers and companies to apply is a popular way in worldwide.

But if you wanna keep your project in private, you might wanna go for GitLab.

GitHub also offers you private projects though you need to pay.

We love free and free of charge is always good (ofc).

And if you’re more Ruby person (I’m Frontend though), some of them prefer using GitLab more.

These are the very quick summary of the difference between GitLab and GitHub.

But if I describe more details differences, GitHub and GitLab have more.

Just another quick look for one more difference, they are different in authentication levels.

In GitLab, you can set and modify people’s permissions according to their role.

You can choose if someone gets a read or write access to a repository.

But in GitLab, you can provide access to the issue tracker without giving a permission to the source code.

So, basically in GitLab, you can work without permissions but you need permissions in GitHub from a project owner.

I’m not gonna write all other small differences though if you’re interested in, this article might help you to know more.

Command sample to make a new branch, commit & push

I share a sample command to show how it flows.

GitLab

Let’s say I wanna make a branch with a name test and have already a project called test-project.

Also, I already have a remote work environment of this project and wanna add a new file README.md.

Means, I have a remote work environment for test-project on my laptop.

$ cd test-project // access a remote work environment on my laptop
$ git branch test // you create a branch with a name 'test'
$ git branch
* master // it means you're in a 'master' branch now
test
$ git checkout test // switsh to a branch 'test' from 'master'
Switch to branch 'test'
$ git branch
master
* test // now, you're in a 'test' branch you made
$ git push origin test // you get messages you created merge request for 'test' branch.
$ git commit -m 'a commit' // you can write any comment in ''
$ git status // check status cuz you got messages no changes added to commit and you see modified files
$ git add README.md
$ git status // check status cuz you see change to be commited
$ git commit -m 'a commit' // any comments you wanna write
$ git log // check a log whether you commited in a right place or not
$ git remote add origin https://gitlab.com/(your username)/(your project name).git
// you can copy URL of your project from GitLab. just paste in above.
// and this is for adding remote work environment on your laptop if you don't have
$ git remote -v // you get messages fetch and push
$ git push -u origin test // you should be able to see on GitLab you success to edit/add files

I left notes next to each command.

You might guess in GitHub, you just need to switch a URL of your project.

That’s right, you just simply switch a URL of your project to the one in GitHub you wanna push.

GitHub

Then I just switch a project URL to a GitHub one, easy!

Just remember GitHub doesn’t have .git in the end of URL.

$ cd test-project // access a remote work environment on my laptop
$ git branch test // you create a branch with a name 'test'
$ git branch
* master // it means you're in a 'master' branch now
test
$ git checkout test // switsh to a branch 'test' from 'master'
Switch to branch 'test'
$ git branch
master
* test // now, you're in a 'test' branch you made
$ git push origin test // you get messages you created merge request for 'test' branch.
$ git commit -m 'a commit' // you can write any comment in ''
$ git status // check status cuz you got messages no changes added to commit and you see modified files
$ git add README.md
$ git status // check status cuz you see change to be commited
$ git commit -m 'a commit' // any comments you wanna write
$ git log // check a log whether you commited in a right place or not
$ git remote add origin https://gitHub.com/(your username)/(your project name)
// you can copy URL of your project from GitLab. just paste in above.
// and this is for adding remote work environment on your laptop if you don't have
$ git remote -v // you get messages fetch and push
$ git push -u origin test // you should be able to see on GitLab you success to edit/add files

Summary

I cut messages you’ll get after typing some commands though it’s because depends on which files and how many of them you commit and push, it looks different.

(Of course, they follow some format but just file names and paths are different.

Plus, sometimes you see deletedtoo. )

In the begginig is weird that after you command right, boom, you get an innitial commit successfully on your GitLab account or GitHub account.

It’s really embarrassing as a developer but I seriously did not have much experience how Git stuffs work till one of my client but a colleague asked me to command … lol

But once you get used to by trying out and using, in my opinion, you’ll get used to.

I’m still learning many things though hope this helps you too!

And always welcome to have a better way or solution based on what I noted.

Then, Tschüß (:

--

--