Most used 8 Github commands

Melih Yumak
Mar 2 · 4 min read

If you are part of development Git is one of the most important tools you can use for development. There are many use cases for the github. You can contribute any open source project you would like to and learn coding with reading the codes of many successful developers.

If you are working with the team using git is inevitable for every developer. Learning github commands and memorizing them might be challenging at the beginning but it will come with time :)

Git clone is one of the most important command.

When you want to clone one of the projects from github there is an https url you can use for git clone.

git clone <repository_url>

When you click the green Code button there is a modal opens for to clone the repository you want.

After you copy the url, open a new terminal and use the git clone command to clone the project.

After you clone the repository when you made some local changes git status is changes and shows you which file is changed according to your changes.

git status

After you made some changes in your code on your terminal (in the project folder) git status will show you which files are changed.

After you see your changed you can add them to next commit or remove, edit. Here the text color is red that states the file is unstaged. Unstaged files does not included in to the commits.

Note: Short format of git status can be used as git status -s

After you successfully made the local changes to include these changes to your commit you need to add them.

Adding single file

git add <filename>

Adding all changes

git add . 

After you successfully added your local changes you can see the status with git status as you can see below modified text color changed to green because its staged right now and it would be included in next commit.

After successfully added your local changes now you can make your commits!

git commit -m "your commit message"

You can think as commits are certain saved points in development. When you commit changes it saves all of your local (staged) changes in to that commit.
You can describe which files you include that commit and what is that commit for in your commit messages.

Note: when you make commits it does only saves your changes to your local environment unless you push them to remote branch.

After you made your commits and worked on the things you wanted its time to push your changes to remote branch. This remote branch will include your commits after you pushed your changes.

git push <remote> <branch name>Ex: git push origin master

If you want to push origin remote and master branch you can use that example above.

After you successfully push your changes your code will be saved in remote repository.

While working on the remote branch with another people when you want to take their commits in to your local branch you can pull them.

git pull <remote>

Now you can continue on your development from the remote repository’s state.

Note: If there are some files changed locally and also on the remote there might be some conflicts. In that case you need to resolve these conflicts.

There might be many branches in single repository. Branches makes development easier.
While you are working on some changes someone else can work on something else. In that case it’s easier to work on another branches and when the development finishes you can merge it to the main branch you are using.

Creating new branch

To create new local branch you can use the command below.

git branch <branchName>

List existing branches

git branch --list 

If you would like to switch another branch you can make it as

Switch branch

To change another branch it needs to be locally available.

git checkout <branchName>Example: git checkout develop

Create a new branch and switch

git checkout -b <branchName>

That command creates a new branch from the current branch you are in and switches your branch to new one.

You can buy me a coffee!

Thank you for reading this far.

Follow me on Medium or Github if you’re interested in more in-depth and informative write-ups like these in the future. 😀



Everything connected with Code & Tech!

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store