What is GitHub and How we use?
Version Controlling
What?
• Managing changes to a source.
• “Management of multiple revisions of the same unit of information"
• Changes are identified using a revision number.
• Each revision has its timestamp as well as the person who done the change.
• Revisions can be restored, compared, and merged.
Why?
• Access control.
• Conflict resolvement.
• Easy collaborative development.
• Easier backups and centralized source code repository.
• Overview of changes performed to a file.
Terminology
• Repository
Central location where contains a collection of files of various different versions of a Project.
• Trunk (Master branch)
This is the place where most stable code is being placed.
• Stage
Mark files for tracking changes.
• Commit
captures a snapshot of the project's currently staged changes.
• Branch
Copy of the master branch taken at a given point. All the developments and bug fixes will be done in a branch. Usually, it is allowed to have multiple branches at the same time.
• Checkout
Mark/Unmark files for changing.
• Merge
Combine branches together to update the master branch.
• Merge conflict
This occurs when merging files which has been changed in two separate branches. Changes that interfere other changes.
Best Practices.
• Use a source control system.
• You need to keep latest version of the file always.
• Checkout only what you need.
• Merge the code with development branch at least once per a day.
• Follow a formal review process when merging.
Git
• Most popular version controlling system.
• Distributed version control system.
• Free and open source.
• Multiple branches and tags.
• Support multiple protocols (HTTP, SSH)
• Staging area, local commits, and stashing.
Staging area - Mark files to be committed.
Local commit - Commit code locally without pushing into the remote branch.
Stashing - Keep file changes in Stash and apply them in a later.
How to make an environment to GitHub
1. Download the GitHub and install GitHub for your device.
(https://git-scm.com/download)
2. Create a GitHub account if you are a new user.
How to create a repository
1. Go to new at the up left corner in home page.
2. Give a valid name for repository and click create repository.
Commands of GitHub
Git Init
• “git init” - Initiate working directory as a git directory.
Go to your working directory and select file path and type “cmd”.
Then command prompt will be displayed. Then type “git init” there.
Git status
• git status - Check the status of the directory.
Git add
• git add -A – Add all files in directory to git. We should add files before committing.
• git add readme.txt – Add a one file to git. (readme.txt = filename)
Git commit
• git commit -m “commit name”
Set repository
• git remote add origin https://github.com/thara99/report.git – Set the repository that we created.
Check repository working correctly
• git remote -v - Check whether repository is able to push and pull.
Git Push
• git push -u origin master – Push the files to master branch. If you need to push files to another branch you can give a branch name instead “master”.
Git Pull
• git pull – Pull files from GitHub.
Git clone
• git clone https://name-of-the-repository-link - Git clone is a command for downloading existing source code from a remote repository.
Git branch
• git branch <branch-name> - Create a new branch.
• git branch or git branch –list – View branches.
• git branch -d <branch-name> - Delete branches.
Git checkout
• git checkout <name-of-your-branch> - Switch to current working branch before start work.
Git revert
1. git log -- oneline – To see out commit history.
2. Then we should specify the hash code next to our commit that we would like to undo.
git revert 1578842
Git merge
1. git checkout dev – Switch to the div branch.
2. git fetch – Update local dev branch.
3. git merge <branch-name> - Merge feature branch to dev.
Stash
1. “git stash -u” - Store current work with untracked files.
2. “git stash pop” - Bring stashed work back to the working directory.
Git cherry picking
• git switch master – Switch to branch you want to apply the commit to.
• git cherry-pick <commit-hash>
• git cherry-pick -x <commit-hash> - If you cherry-pick from a public branch
• git notes copy <from> <to> - If you have notes attached to the commit they do not follow the cherry-pick.



0 Comments