-
Version Control System
-
Git
- local software to keep track of changes
- command line tool
-
GitHub
- Online git repo hosting platform with many collaboration features
-
GitHub Desktop
- git client tool to make it easy to work with git and github
- easy git config set up
- provide name and email
- link text editors like sublime or others
- easy Github.com account connection
-
Working Direcory (Project folder)
- This is where all the projects file stay
-
Local Repository
- This is where git keep track of chanegs
.gitfolder- Commits :
- The changes from last point till this point
- Name and email of the author of this commit
- Commit message
- SHA : a comination of letetr and number to uniquely identify this commits
-
Staging Area
- This is an hyphothetical area in between your working directory and Local repository
- You can visualize it as changes tab in GitHub Desktop or IntelliJ
-
Remote Repository
- The repository under Github.com
- Can be shared on internet publicly
- Can be connected to local repository
-
Ignoring the files we do not want to keep track of
.gitignorefile is a special file that git use to stop git from keeping track of the files in the list seprated by new line
your filename here your another file name here your folder namem here or your pattern to describe files or folder
-
Creating java project and setting up local repo
-
Adding
.gitignorefile -
Making initial commit by selecting all unversioned files
-
Making more commits to do more work
-
Publishing repository to remote GitHub.com
- Github.com remote repository has been created for you by Intellij directly
- Connection between local repo and remote repo is established
- local commits get pushed to remote repository
-
Now do more work make more commits
-
Now we can simply
pushthe local commits to remote -
If we have commits in remote repository that we do not have locally ->
pull
When you clone ,
- It will get remote repository to your local computer
- It will have connection with the remote repo
- It has all the history of that repo
- If you own this remote repo , you can directly push more commits back to remote
We can go back in time in history and remove all the history from that point on
1-2-3-4-5 commits
reset -- hard 3
--> 1-2-3 and all changes in 4-5 will be lost
reset soft-mixed 3
--> 1-2-3 and 4,5 will be gone from history but the changes still be there
Branching allow you to work on new code without affecting the existing code safely. It's like opening new timeline.
If you are satisfied with our work you can merge the changes into main timeline master branch.
- Create a new branch called
list - Create a new class under
day3package calledListPractice - Make few commits under this branch by making few changes
- Move your head to master
- Merge
listbranch intomaster
- Create a new branch called
set - Create a new class under
day3package calledSetPractice - Make few commits under this branch by making few changes
- Move your head to master
- Remove the
--no--ffoption before merging - Merge
listbranch intomaster
- Create a new branch
tc100 - Update the movie class and make few commits
- now let's
checkout masterand generate conflict by updating same Movie class with different content - commit this change in master
- Merge
tc100into master and deal with the conflict in 4 ways:- Abort the merge (
git->Abort merge) Accept Theirsto keeptc100version of the changeAccept Yoursto keepmasterversionmergeto have custom content as merge result
- Abort the merge (
- Create a new branch
tc200 - Create new Class called
Car - Make some changes and do 2 commits
- now let's
checkout master - Create a new class called
Animal - commit this change in master
- Merge
tc200intomasterand see the result - CONFLICT OR NO CONFLICT ? NO
- Push all your local master commits to stay in sync with the remote
- Go to Github.com and update
FromGitHub.txtfile with different content and commit directly on Github.com - Now from IntelliJ
fetchto see the commit from the remote (just to get the info) Update Project(pull) to get this changes from remote to local --> No conflict
- On your local, update
FromGithub.txtand commit - On your remote , update
FromGithub.txtwith different content and commit (to simulate your team member pushed different update) - On your local , try to push this changes , it will be rejected because you have to
pulldown the changes before you canpush - It will give you option to
pullandmergeclick on merge and boom! conflict !! - Now resolve the conflict with the technique you learned previously
Accept Theirsto keeptc100version of the changeAccept Yoursto keepmasterversionmergeto have custom content as merge result
- Now Push your result to the remote
- This is very common scenario while working with team members
Merge Conflict - can happen while you have commits in your master branch that the feature branch you are working on , and both of the commits editing same file with different contect
- Abort merge
- Accept Theirs (keep feature branch version)
- Accept Yours (keep the master branch version)
- Merge (have custom output)
Make sure you head is on master and there is no uncommitted changes
- Create a branch called
collection - Create new package called
day4. - Create a new class called
Conflict - Make a commit for creating file
- Add this text inside main method as comment :
This is collection branch content - commit this change with meaningful commit message
- Move your
HEADto master - Create a package with same name called
day4 - Create a new class with same name
Conflict - Edit the file with the text inside
This is master branch content - Make a commit and merge --> BOOM --> CONFLICT!!! resolve it
- In our case , we used last option with
custom outputas merge result
- create a new branch called
collection2 - Add a comment in the class
Conflictwith this messageMORE WORK ON COLLECTION2 - Commit this change
- Checkout
master - Add a different comment in the class
ConflictwithThis is the change collection2 branch does not know about - Commit this change into master
- Now
mergethecollection2branch and boom! Conflict!!
A light weight flow for collaboration
- Create a branch called
us-100 - Add a class called
TC001underday4package - Make few commits with good commit message
- NOW:
Pushyour branch to remote - This will push your local
us-100branch to remote (newly created)origin/us-100branch - Now go to your GitHub repository main page and observe Green
Compare and Open Pull Requestbutton show up. - Click on it and it will open up pull request creation page
- Add subject to describe what this change is about
- Provide description in description section for more information
- And Click Create Pull request
- This is where conversation , code review can happen
- After all the review , team-member or assigned person can merge your code so it can be in origin/master
- Now back to IntelliJ ,
- checkout
masterbranch pulldown the changes by going togit->update project
- checkout
- Now you are in sync with the remote
- Set up Group project with name : group-YourGroupNumber-project
- Team Lead or (desinated person in the team) create the project
- Set up local repo, add .gitIgnore file , make initial commit
- Publish the local repo to GitHub.com remote repo
- Invite Team members as collaborator using their Github username
- Team members set up
- Provide your GitHub username to Team Lead
- Accept the invitation in your email
- Clone the repository to IntelliJ
- Start collaborating with GitHub Flow
- create a branch with your name and test case number you are working on
for example :
abbos-tc100 - (just to avoid any conflict to start with)
- Create a package with your name
- Create a class with your test case name like
TC100or something like that - do some commits
- push your branch to the remote
- open pull request with proper description and details
- let your team member review your code
- eventually let them merge your code
- you do the same for your team members
- checkout master and pull down the changes from the remote
- start another branch and repeat the process forever
checkout the short for the details
General rule is nobody should push to the master branch , no code should go to master branch without going through GitHub flow, but right now there is no rule to prevent that.
- No code should go to master without pull request
- No pull request should be merged without at least one review approval
- Merge button should not be available if above criteria not met
- in GitHub repo
- team lead (AKA owner of the repository) go to
Setting-> - Select
Branchesfrom left tab - Click Add rule
- Type
masterfor Branch name pattern - Check below checkboxes
- Require pull request reviews before merging
- Optionally select how many review needed (default is 1)
- from all the way down Include administrators (this will block owner from pushing to master directly)
- Click
Createbutton to save - Now no code will be merged without at least one review of pull request
- team lead (AKA owner of the repository) go to
Forking is a process of copying someones public repository under your account.
A common way of collaraboring for open source projects.
When you fork a repository it will create a copy under Your GitHub Account
When you clone , you are just downloading the remote repo into local repo
- I started an awesome project and shared on Github
- Now you want to contribute the project , but I don't know you and I do not feel comfortable adding you as collaborator
- I still want to see your contribution
- You
Forkmy repository so it can get a copy of my repo under your GitHub.com account - Since you own this copy , you have full access to push
- Clone your copy under your IntelliJ
- Now you can open pull request under pull request tab from
your/orgigin/mastertomy/orgin/master - you are requesting to merge the changes you made to reflect on my repository
- If I approve this , your code will be merge under my repo