GitHub Commands

GitHub is a code and hosting platform for version control and collaboration. It lets team member to work from anywhere. This page describes the essentials like repositories, branches, commits, and pull requests.

  1. To configure the author name and email address to be used with commits, use following commands.
    git config –global user.name “Your Name”
    git config –global user.email your_email_address
  2. To create a new local repository: git init
  3. Checkout a repository(create a working copy of local repository): git clone /path/to/respository
  4. Create a working copy of remote repository: git clone username@host:/path/to/repository
  5. Add a file to staging: git add <filename>
  6. Add all file to staging: git add *
  7. Commit changes to head: git commit -m “Commit message”
  8. Commit all the files added to staging: git commit -a
  9. Push all the changes to remote branch: git push origin <remote_branch_name>
  10. To see all the changed file that are yet to be added to staging or not committed: git status
  11. Create a new branch and switch to it: git checkout -b <branch_name>
  12. Switch from one branch to another branch: git checkout <branch_name>
  13. List all the branches: git branch
  14. Push the branch to remote repository: git push origin <branch_name>
  15. To merge a develop branch into feature branch(assuming user is in feature branch):
    git merge <develop_branch>
  16. Preview all the changes before merging: git diff <source_branch> <target_branch>
  17. Set remote upstream branch for local feature branch: git push -u origin <branch_name>
  18. To cherry-pick a commit from branch main-branch into feature-branch, switch to feature-branch, perform git pull and then perform cherry-pick using following command.
    git cherry-pick <commit-hash>