The Most Brilliant Developers Should Know Common Git
Git has provided a lot of advantages for developers. To use it effectively, you should know common git commands and how they work. In this article, we will give you essential information. Keep reading.
Git on Terminal vs GUI
Many GUI-based Git tools are easy and effective for developers to use. Therefore, some of them jump straight into Git with a GUI tool. They feel comfortable with it for a long time. However, later, they recognize that it’s not really easy to run Git commands on the terminal. If you want to know Git in a better way, we suggest using the terminal. You will find it easier and more convenient to use Git this way. In addition, you can control what’s happening when you conduct to trigger a command.
We list some of common Git’s use for you as followings:
How to clone a repo
Create a branch and how to edit the code
Add a set of files to stage 'em
Mke a local commit to the branch
Pull code
Push commits
Common git to work with local repositories
git init
The command will turn a directory into an empty Git repository. You need to do this first step before creating a repository. When you run the git init, you can add, commit files/directories. It is completely possible.
git add
This command helps to add files in the to the staging area for Git. We have to add a file to the Git index (or staging area). Then, it is available to commit to a repository. We have some different ways to use git add. Accordingly, you add entire directories, specific files. It’s also possible for all unstaged files.
You have done some changes to the files. Then, you want to record these changes to a local repository. The git commit is a good common git command. It helps you to reference easily due to each commit has a unique ID.
The command contains a different message. Each commit explains the changes made in a commit. When you add a commit message, it helps to find a particular change or understand the changes.
git status
If you use the git status, it will return the current state of the repository. This common git returns the current working branch. There is a file is in the staging area, but not committed. Then, it will show with git status. Additionally, if there are not any changes, it will return nothing to commit, and the working directory is clean.
git config
The common git has as many configurations and settings as possible. The git allows you to assign these settings. There are two main settings including user user.name and user.email. These values will set up an email address and name commits. They will be from a local computer. With this git config, people use a global flag to write the settings to all repositories on a computer. By contrast, the global flag settings will apply to the current repository that you are in only.
In addition, we can edit many other variables with the git config. You can edit color outputs to turning the behavior of git status.
git merge
This is one of the most common git commands for the developer in coding. It supports integrating branches together. The git combines the changes from one branch to another branch. For instance, it will merge the changes done in a staging branch into the stable branch.
Common git to work with remote repositories
git remote
You can use this git to connect a local repository with a remote repository. The remote repository can have a name set. Thanks to this, you do not have to remember the URL of the repository. Note that the remote repository can get any name. Therefore, you should name the remote repository ‘origin’.
git clone
If you need to create a local working copy of an existing remote repository, the git clone can help. You are able to copy and download the repository to a computer. When you work with the remote repository, cloning is similar. Git will create a directory locally including all files and repository history.
git pull
You want to have the latest version of a repository, let run the git pull. It will pull the changes from the remote repository to the local computer.
git push
The git push is considered as a common git command. It can send local commits to the remote repository. The git requires two parameters. They are the remote repository and the branch that the push is for.
Advanced Git Commands
git stash
Do you want to save changes made when they’re not in a state? The git stash is a good solution. It is to commit those changes to a repository. It stores the work and makes the working directory clean. For instance, when you work on a new feature that’s not complete. However, there is an urgent bug needs your attention.
git log
It is used to display the chronological commit history for a repository. It helps provide context and history for a repository. This git is available instantly on a recently cloned repository to see history.
git rm
You can remove files or directories from the working index (staging area) with this common git command. We have two options: force and cached. You run the command with force deletes the file. The cached command helps remove the file from the working index. A recursive command is necessary to remove an entire directory.
Sum up
If your company has good developers who know Git, it’s a big advantage. The code repositories are clean as always. It’s easy to maintain the code and branches. There are more responsibility and accountability among developers. Additionally, they can carefully use client code repositories with maintaining proper code history. Knowledgeable developers will not repeat the mistakes elsewhere. Both clients and CTOs will be very happy to see their code being managed well.
[Collective Sources]
---
JT1 - IT Recruitment Agency
Email: hi@jt1.vn
Phone: +8428 6675 6685
Website: http://www.jt1.asia
Blog: http://www.jt1.asia/blog
Facebook: https://www.facebook.com/jt1asia