mastering git: the only essential commands you need to know to be a productive developer [pt 1] 🔥
Khem Sok
Posted on February 5, 2023
intro
git is something all programmers have used or will use one way or another. with its vast number of commands and options, it can be overwhelming for someone that is just starting out. learn these few essential commands and you'll be 80% there with your journey with git.
1 - git init
this command is used initialize a new git repository. it creates a .git folder wehre all of the version control information is stored.
git init # to initialize a repository
2 - git clone
this command is used to clone an existing repository from a remote server to your local machine.
git clone https://github.com/user/repo.git # to clone a repository
git clone https://github.com/user/repo.git another-repo-name # to clone a repository and give it a different local name
3 - git add
this command is used to add changes to the staging area.
git add . # to add all changes in the current directory
git add file.txt # to add changes in a specific file
4 - git commit
this command is used to save changes to the repository. the changes can be a single file or multiple files. when you run git commit, you'll be prompted to write a commit message to describe the changes you've made.
git commit -m "commit message" # to commit changes with a message directly from the command line
git commit -a # to commit all changes in the repository
5 - git push
this command is used to push changes from your local to a remote repository.
git push origin main # to push changes to the remote repository named "origin" and the branch named "main"
git push -u origin main # to set the upstream branch for "origin/main" to "main"
6 - git pull
this command is used to retrieve changes from a remote repository and merge them into your local repository.
git pull origin main # to get changes from the remote repository named "origin" and the branch named "main"
git pull --rebase # to reapply your local changes on top of the changes in the remote repository
7 - git checkout
this command is used to switch between different branches in the repository. branches allow you to work on different version of the project.
git checkout -b new-branch # to create a new branch named "new-branch" and switch to it
git checkout branch-name # to switch to an existing branch named "branch-name"
conclusion
these are the seven essential git commands that you need to get started. mastering these command, and you'll be on your way to become a git expert.
Posted on February 5, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.