DEV Community

Cover image for Usage of Basic Git commands and Github in 5 minutes
Thu Htet Tun
Thu Htet Tun

Posted on

Usage of Basic Git commands and Github in 5 minutes

Hello guys,

I would like to share some of basic git commands for you. This is not kind of specific documentation. I collected it for my learning process in git last year. Before you read, please note that all are written in informal style like a sketch.

Anyway, I hope it may help you to know some basic git commands and github in one place.

Let's start..

Git Basic Commands

git init = create new git repo
git status = check modify files
git add . = add modify files into stage
git commit -m "type message" = commit files with messages
git log = show history of commit
git log --oneline = show history of commit in short way

git checkout = switch to commit file
git reset --head = Delete commit file

git branch -a = show all branch in repo
git branch = create new branch in repo

git checkout = switch to branch
git checkout -b = switch and create new branch in repo

git branch -D = Delete existing branch before merge
git branch -d = Delete existing branch after merge

git merge = when you have to merge, first switch to the branch which is merged. Then, git merge and run it. If conflict when merge, fix in the code file and,
git add .
git commit
then sound a screen, you need to press shift+; and type :wq to escape that screen.
It will merge as perfect.

Github [remote repository management]

Create Github Account
Create New repository

1. How to Upload Your local Repo to Github

open your local repo directory in cmd or gitbash
check if there is nothing left to commit with git status,

git push
In this case, everytime you want to push, url of remote repo is too long to add.
So, Let's give an alias name(short name) for url of remote repo.
By this command,
git remote add
git push origin

2. How to clone Remote Repo to Your Local Machine

git clone
At this time, github originally add remote url alias name as origin (you don't have to change)
By push,
git push origin

Collaborating between Developers [pull request]

When you are in different branch and push into remote repo.
Other developers and your manager exists and they review your code.
In this case, your pushed code have to be a pull request.
Others reviewed and comment on it.
Then, everyone approve -> merge into master

Fork [contributing]

Some open soure project or some public source code are free.
you can fork them into your github account.
Then, clone in local repo
changes files
push to your github account.
Create pull request to parent open-source project or source-code.
Then, owner of project review and comment your changes and
only owner can merge your codes into parent project.

Yeahhh.. Thank you for reading till the end. That's all for basic usage of git and github that I collected. Please let me know in comments if you have any questions for me.

Thanks guys!

Top comments (0)