In this post, we will see some Git commands that can help us to manage our projects.
It is used to start a new repository.
git init 'repository name'
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"
It is used to add files to the staging area.
git add .
It is used to save our changes.
git commit -m "message"
It is used to show the differences between files that we haven’t saved yet.
It is used to show the status of the current branch.
It is used to show the history of the current branch.
It is used to push our files from the local repository to the remote repository.
git push "url remote repository" "branch name"
It is used to get the latest version from the remote repository.
git pull "url remote repository"
It is used to manage branch.
[List of all branches]
[Create a new branch]
git branch "name new branch"
[Delete a branch]
git branch -d "branch name"
It is used to switch from one branch to another.
git checkout "branch name"
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"
It is used to merge a branch with another.
git merge "branch that we want to merge in the selected branch"
We have the branch called “branch_new_Change” where the file main.js is this:
Instead, in the branch “master” the file main.js is this:
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:
Then, we have to run the command:
git merge branch_new_change
And now, if we check again the main.js file in the “master” branch, this will be the result:
It is used to create a local working copy from a remote repository.
git clone "url remote repository"
OBVIOUSLY, THESE ARE ONLY SOME EXAMPLES OF THE GIT COMMANDS BUT, IF WE WANT TO KNOW THE COMPLETE LIST, WE CAN LOOK UP THE GIT WEB SITE.