DEV Community

Hasan Elsherbiny
Hasan Elsherbiny

Posted on

Top 10 GIT Commands

after discussing what is git in the previous article, in this article we are mentioning the most 10 commands you need to get started with GIT

git init:
Enter fullscreen mode Exit fullscreen mode

Initializes a new Git repositry in the current directory

git clone [repository_url]:
Enter fullscreen mode Exit fullscreen mode

Clones an existing Git repository from the specfied URL to your local machine

git add [file(s)]:
Enter fullscreen mode Exit fullscreen mode

Stages changes for commit. Use git add . to stage all changes in the current directory.
git commit -m "commit message":

Commits the staged changes along with a descriptive commit message.

git pull:
Enter fullscreen mode Exit fullscreen mode

Fetches changes from a remote repository and merges them into the current branch.

git push:
Enter fullscreen mode Exit fullscreen mode

Pushes your local commits to the remote repository.

git branch:
Enter fullscreen mode Exit fullscreen mode

Lists all branches in your repository. Use -r to see remote branches and -a to see all branches.

git checkout [branch_name]
Enter fullscreen mode Exit fullscreen mode

Switches to the specified branch. You can also use this command to create a new branch.

git merge [branch_name]
Enter fullscreen mode Exit fullscreen mode

Merges changes from the specified branch into the current branch.

git log:
Enter fullscreen mode Exit fullscreen mode

Shows a log of all commits in the current branch, including commit hashes, authors, dates, and commit messages. Use --graph for a visual representation of branching.

These commands provide the basic functionality needed to work with Git effectively.
Depending on your workflow and project requirements, you may need to use additional Git commands and options for more advanced tasks.

Top comments (2)

Collapse
 
robertraff1 profile image
RobertRaff1

also git diff is very important command especially when you need to examine your branch to find out differences

Collapse
 
hasanelsherbiny profile image
Hasan Elsherbiny

yes this is true