GitHub is a platform used by millions of developers worldwide for version control, collaboration, and code sharing. Whether you’re a coding newbie or an experienced developer, mastering GitHub commands is key to becoming more productive. In this guide, we’ll walk through the most important GitHub commands you should know to get started.
1. git init
This command is used to initialize a new Git repository. It sets up all the necessary files in the current folder so you can track changes in your project.
How to use it:
Open your terminal, navigate to your project folder, and type.
git init
2. git clone
When you want to copy a project from GitHub to your local computer, you use git clone
. This downloads the project and its entire version history.
How to use it:
In your terminal, type:
git clone
3. git status
This command shows the current state of your project. It tells you if any files have been modified, added, or deleted since the last commit.
How to use it:
In your terminal, type:
git status
4. git add
When you make changes to your project, you use git add
to include those changes in your next commit. This moves the changes into the “staging area.”
How to use it:
If you want to add a specific file:
git add
to add all changes in your project.
git add .
5. git commit
After adding changes to the staging area, you use git commit
to save those changes to the project history. Each commit should have a short message describing what you’ve done.
How to use it:
Type the following command to commit your changes:
git commit -m "Your commit message here"
6. git push
git push
is used to send your committed changes to a remote repository, like GitHub. This is how your changes get uploaded for others to see or collaborate on.
How to use it:
git push origin
7. git pull
git pull
is used to fetch changes from a remote repository and merge them into your local project. This ensures you’re working with the latest version of the project.
How to use it:
git pull origin
8. git branch
This command helps you create, list, or delete branches in your project. Branches are used to work on different features or versions of a project without affecting the main version.
How to use it: To create a new branch:
git branch
To list all branches.
git branch
To delete a branch.
git branch -d
9. git checkout
git checkout
lets you switch between branches or restore files. This is useful when you want to work on a different part of the project or revert changes.
How to use it:
To switch to another branch:
git checkout
To restore a specific file to its previous state.
git checkout --
10. git merge
git merge
is used to combine changes from one branch into another. Typically, you’ll merge your feature branch into the main branch once your feature is complete.
How to use it:
First, switch to the branch you want to merge into (usually the main branch):
git checkout main
Then, merge the other branch.
git merge