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.
- 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 - To create a new local repository: git init
- Checkout a repository(create a working copy of local repository): git clone /path/to/respository
- Create a working copy of remote repository: git clone username@host:/path/to/repository
- Add a file to staging: git add <filename>
- Add all file to staging: git add *
- Commit changes to head: git commit -m “Commit message”
- Commit all the files added to staging: git commit -a
- Push all the changes to remote branch: git push origin <remote_branch_name>
- To see all the changed file that are yet to be added to staging or not committed: git status
- Create a new branch and switch to it: git checkout -b <branch_name>
- Switch from one branch to another branch: git checkout <branch_name>
- List all the branches: git branch
- Push the branch to remote repository: git push origin <branch_name>
- To merge a develop branch into feature branch(assuming user is in feature branch):
git merge <develop_branch> - Preview all the changes before merging: git diff <source_branch> <target_branch>
- Set remote upstream branch for local feature branch: git push -u origin <branch_name>
- 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>