The Most Usable Git Commands
GitHub is a most usable collaborative tool for a software developer. Because if you are a developer, you have to work with a team. Therefore you want to share your codes with others. Not only codes, you can share any documents using this tool. you need to share those things to the GitHub. For this you can use command line to share your codes. Nowadays we can see many tool otherthan command line to share your codes easily to GitHub like GitKraken. But, In the industry we can see many of them are used command line. Because of that as a developer you need to know most usable git commands. Now, Let’s see what are the most usable git commands.
1. Git clone
Git clone is a command for existing codes from a repository. In the other words, git clone is basically does connect existing repository with your github account and save that repository in your computer.
git clone <repository-link>
As an example, one of a developer in your project team create a repository and share the repository linked with you. Now, you want to clone that repository and save it to your computer.
First, you need to go that repository via inviting link and copy the link (The above highlighted link). After you need to paste the link in the command line under the git clone command.
Git status command gives all the details of the current branch.
From using this command, we can see,
- if there is anything to commit, push or pull
- files are staged, unstaged or untracked
- there are any files or codes modified, created or deleted
When you clone a repository you can change codes in your computer. After change the original codes you cannot pull another codes without commit your changes. But, you don’t want to add your changed codes into the original code. Therefore, you can use Git stash command, it takes your uncommited changes saves them away for later use.
4. Git pull
Git pull command gives new updates of remote repository. From this we can take new changed codes which others changed. Before using git pull command, you should use git stash or git pull command. if you use git stash command you can see original code without your changes. otherwise, If you use git push command you can see the code with your changes.
5. Git stash apply
After pull the codes which other developers are changed, from remote repository you can add your changes to that code. git stash and git stash apply are interconnected.
git stash apply
6. Git commit
After you changed your original code you want to save those changes. For that you can use git commit command. As well, while you commit changes you need to write a short description to explain what you have developed or changed. Otherwise, others cannot find what are the changes you did.
git commit -m "short Description"
After you committed your changes you need to share them into remote repository. Git push command uploads your commit to the remote repo.
git push <remote> <branch-name>
As well, if you create a new branch, then you add that as follow:
git push --set-upstream <remote> <branch-name>
git push -u origin <branch_name>
If your repository is not save in c folder, first you should give your path to command line. first, go to the folder where you save your repository. After click the path and write cmd and click enter. According to that you can take your folder path in to the command line.
In addition, there are many git commands you need to use in your daily programming. Those are my most used git commands I come across my daily programming. I think you learn something this article.
Thank you for reading!