In this post, we will see some Git commands that can help us to manage our projects.
git init:
It is used to start a new repository.
git init 'repository name'
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/1-5.png)
git config:
It is used to set the name and the email to use with our commits.
git config --global user.name "name"
git config --global user.email "email"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/2-1.png)
git add:
It is used to add files to the staging area.
git add .
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/3-1.png)
git commit:
It is used to save our changes.
git commit -m "message"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/4.png)
git diff:
It is used to show the differences between files that we haven’t saved yet.
git diff
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/1-6.png)
git status:
It is used to show the status of the current branch.
git status
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/2-2.png)
git log:
It is used to show the history of the current branch.
git log
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/8.png)
git push:
It is used to push our files from the local repository to the remote repository.
git push "url remote repository" "branch name"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/3-2.png)
git pull:
It is used to get the latest version from the remote repository.
git pull "url remote repository"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/4-1.png)
git branch:
It is used to manage branch.
[List of all branches]
git branch
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/5.png)
[Create a new branch]
git branch "name new branch"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/6.png)
[Delete a branch]
git branch -d "branch name"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/7.png)
git checkout:
It is used to switch from one branch to another.
git checkout "branch name"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/1-7.png)
git tag:
It is used to give a tag to a specific commit; if we don’t specify the commit ID, it will add the tag at the latest commit.
git tag [tag_name] [commit_SHA] -m "Tag message"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/9.png)
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/10.png)
git merge:
It is used to merge a branch with another.
git merge "branch that we want to merge in the selected branch"
For example:
We have the branch called “branch_new_Change” where the file main.js is this:
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/3-3.png)
Instead, in the branch “master” the file main.js is this:
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/4-2.png)
Now, if we want to push the version of the main.js file from the “branch_new_change” in the “master” branch, we have to select the “master” branch:
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/5-1.png)
Then, we have to run the command:
git merge branch_new_change
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/6-1.png)
And now, if we check again the main.js file in the “master” branch, this will be the result:
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/7-2.png)
git clone:
It is used to create a local working copy from a remote repository.
git clone "url remote repository"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2023/02/1-8.png)
OBVIOUSLY, THESE ARE ONLY SOME EXAMPLES OF THE GIT COMMANDS BUT, IF WE WANT TO KNOW THE COMPLETE LIST, WE CAN SEE IN THE GIT WEB SITE.