Git : Understanding basic commands and some useful tips

En Ting
Qumon Intelligence
3 min readJun 9, 2022

--

This chart explains the data flow using git commands

I believe git is not something new for programmers. Today I would like to explain some basic git commands so you will have better understanding about these commands while executing them.

1 — git clone <<project repository>>

This fetches the project from the source , downloads all the files from repository and stores in your local computer. You may use this command to fetch a project from Github/Bitbucket/Gitlab with public access.

2 — git checkout master

This checkouts the project from master branch of local repository.

3 — git pull

This pulls all the project files from the branch you have been checking out from.

4— git checkout -b <<branch name>>

It creates a new branch with the specified branch name in local repository.

5— git add .

This stages the changes of all files. You may understand as it saves the changes of all files in current project. Otherwise, you may run “git add <<specify filename>>” to save a specific file or multiple files with whitespace in between the filenames. Here’s an example to stage multiple files, “git add file1 file2”.

6— git commit -m “add a comment here”

This commits your changes to local branch and adds a comment which will be shown in remote repository. At this particular time, changes have not been pushed to remote repository yet.

7 — git status

It will display branch information (which branch you are currently checking out with) and uncommitted changes (both staged and unstaged)

8 — git stash

It temporarily saves uncommitted changes (both staged and unstaged) for later use. Be aware that stash is local to your git repository.

9 — git stash pop

It removes the changes from the stash and reapplies them to your working copy of current branch.

10 — git stash apply

It reapplies the changes from the stash to your working copy of current branch and keep the new changes in the stash.

11 — git push origin <<branch name>>

It creates a new remote repository with the specified branch name and pushes all the files from local repository to remote source.

12— git branch -D <<branch name>>

It removes the local branch. You cannot remove existing branch you are currently checking out.

13— git push origin — delete <<branch name>>

It removes the remote branch.

Some of us may work with peers with the same remote repository and sometimes we might encounter merge conflicts. To avoid merge conflicts, you may follow the practice below:

Step 1 — Always work under master branch

Step 2 — Pull the latest changes from master branch before creating a new branch

Step 3 — Creates a new branch, stage, commit, and push your changes to remote repository

Step 4 — Done!

Feel free to try it out and let me know if you have other better way of avoiding merge conflicts too.

--

--