GitHub is a powerful source code repository tool. It enables the development team to collaborate and work together, merge and track the changes.
In this blog, we will see the list of useful GitHub commands a developer must know if he or she is working with the GitHub repository.
List of commonly used GitHub commands
- To check the version of Git: git –version
- To Initialize Git on the current directory: git init
- Clone/ Retrieve entire repository from a location: git clone <URL>
- Set the user name for the current repository to “repo-test”: git config user.name “repo-test”
- Check the status of the Git: git status
- Add index.html to the Staging Environment: git add index.html
- Stage all new, modified, and deleted files. Use the shorthand command: git add -A
- Commit the changes to the current repository with the message “First release!”: git commit -m “First release!”
- Find differences of what is changed but not staged: git diff
- Find differences between what is staged but not committed: git diff –staged
- Check the compact version of the status for the repository: git status –short
- Commit the updated files directly, skipping the staging environment: git commit -a -m “Code Added”
- View the history of commits for the repository: git log
- Show all git possible commands in the command line: git help –all
- Create a new branch: git branch <branch name>
- List the existing branches: git branch
- To move to a new branch: git checkout <branch name>
- Create, and move to a new branch with the name hello-you: git checkout -b
- Merge the hello-you branch with the current branch: git merge
- Remove the hello-you branch from the local repository: git branch -d
- Add a remote repository as an origin: git remote add origin
- Get all the change history of the origin for this branch: git fetch origin
- Merge the current branch with the branch master, on origin: git merge origin/master
- Update the current branch from its origin using a single command: git pull origin
- push the current branch to its default remote origin: git push origin
- List all local and remote branches of the current Git: git branch -a
- List only remote branches of the current Git: git branch -r
- In .gitignore add a line to ignore all .exe files: *.exe
- In .gitignore add a single line to ignore all files named temp1.log, temp2.log, and temp3.log: temp?.log
- Ignore all .log files in .gitignore, except main.log: *.log !main.log
- Show the log of the repository, showing just 1 line per commit: git log –online
- revert the latest commit: git revert HEAD
- Amend the previous commit with the message “Updated index”: git commit –amend -m “new update”
I hope I have covered all useful GitHub commands. You may use the list of commands as a Git Cheatsheet.
Keep Following: SharePointCafe.NET