Introduction to GitHub Commands
GitHub is very much popular web-based application in current industry for hosting variety services targeting version control using GIT commands. It offers various distributed version controlling as well as source code management properly.
Some of the basic commands used by GitHub are as follows:
- Commands for getting existing projects and create one new GITHUB projects:
- Git init: Suppose developer needs to prepare one new repository in his local environment. For initializing the same they have to use init commands, which helps them for initializing GitHub project repository locally.
- Git clone ssh://something.com/[username]/[repository_name].git: Suppose developer needs to create one specific repository of GITHUB in their local copy from the specific remote location. Then they have to execute clone command for copying the same remote repository in the local environment in specific location.
- Some of the basic commands for continuing with GITHUB:
- Git status: This GitHub command is mainly used for identifying GIT created status in local repository. It provides proper information between a syncing status of local and GITHUB repository to the end user.
- Git add [file_name.doc]: Used for adding one specific file in staging area.
- Git add –A: Adding all the files whether it is new or modified will be added in the staging area.
- Git commits –m [“message for commit”]: Commit all the required changes.
- Git rm –r [file_name.doc]: Helping for removing the file or any defined folder.
There are several other popular commands which are used by the developer, which are not very basic commands but working with GITHUB more, those commands are very much required to execute. Some of these kinds require intermediate commands which are mentioned below:
- Command for Branching and Merging multiple projects commits codebase:
- Git branch: This is very much a useful command for using any kind of GITHUB set up for your projects. It normally provides entire branch information in a list. Asterisk denotation is also given which points the exact current project.
- Git branch -a: This is helping for listing all the available branches considering all the locations of the branches, it can be local or remote. It is one of the key commands for identifying all the available projects in GITHUB environment.
- Git branch [branch_name]: Creating a new branch with new name.
- Git branch –d [branch_name]: Deleting a specific branch.
- Git push origin –delete [branch_name]: Deleting a branch from the remote environment.
- Git checkout -b [branch_name]: Helping to create one specific new branch and switching entire codebase to it.
- Git checkout –b [branch_name] origin/branch_name: Helping for cloning one remote branch and switching entire codebase to it.
- Git checkout [branch_name]: Switching to a defined branch.
- Git checkout – Switching to a specific branch which absolutely checks out last.
- Git checkout – [file_name.doc]: Avoiding or discarding the last changes in the specific file.
- Git merges [branch_name]: Helping for merging one specific branch with one of the other activities available branches.
- Git merges [source_branch] [target_branch]: Helping for merging with specified sourcing branch and specified target branch.
- Git stash: Stash helps in some of the specific changes to define dirty directory immediately.
- Git stash clear: Removing all the stash entries from the dirty working directory.
Still, some of the critical tasks need to be done by the GitHub users frequently. Those tasks also have some advance kind of commands which needs to be executed, and which are mainly used by some of the managerial people for understanding projects status comparing other existing project and also sometimes used for sharing some project knowledge with others. These advanced commands are mentioned below:
- Commands for updating or sharing projects data:
- Git push origin [branch_name]: Helps for pushing one of the created branches in your local environment to a remote directory or repository.
- Git push –u origin [branch_name]: It does the similar task like above, pushing entire local repository branch to the remote repository, extra utility of using this command is also remembered for this specific branch for future reference.
- Git push: Again it does the same task, pushing entire local repository data to remote, but do not need to mention the branch name, it will pick up branch name directly from the last remembered branch.
- Git push origin – delete [branch_name]: Deleting specified branch.
- Git pull: Helping for updating all the newest commit in the mapping local repository.
- Git pull origin [branch_name]: Helping for pulling entire changes from the remote repository to local.
- Git remote add origin ssh://something.com/[user_name]/[repository_name].git: Helping for mapping local repository’s origin branch with remote repository through SSH.
- Commands for Comparison or specific inspection on GITHUB repository:
- Git log: Displaying all the log information of one specific project, which can provide every information with committed changes.
- Git log –summary: Provide more log details for identifying specific members who committed the same.
- Git diff [source_branch] [target_branch]: This one normally is used before merging on a specific document. It helps for displaying current changes done on the existing document.
Tips and Tricks to Use
Some common users who very frequently use GitHub utility normally use some of the tips and tricks for utilizing GitHub commands output in proper way. Those kinds of tricks are normally used for solving some user-specific queries and display screening output for understanding the same properly. Some of the very commonly used key tricks are:
- Suppose GitHub user needs to identify the difference between two versions of the document. In that case, if that document holds a lot of whitespaces, it will also display the same. So user sometimes needs to ignore those whitespaces, so one of the very commonly used tricks for that is ‘?w=1’, which helps to display only the code changes without any whitespace.
- GitHub user needs to display those changes which are committed by one specific user, so including query string like ‘?<user_name>’ will give them the result of all the committed changes done by that specific user.
Github is one of the key repository tool currently available in the industry. A lot of organization are really willing to use GitHub due to their repository mechanism, and well documentation on internet. Github also provides proper view representation from there anyone will be able to commit or checkout easily. All those commands may not be required to be executed. But still executing command performance is always been better than normal view.
This has been a guide to GitHub Commands. Here we have discussed basic, intermediate as well as advanced GitHub Commands along with tips and tricks to use. You may also look at the following article to learn more –