Git GitHub Consolidated
Git GitHub Consolidated
Git-GitHub-Consolidated Page 1
Git-GitHub-Consolidated Page 2
Git-GitHub-Consolidated Page 3
Git-GitHub-Consolidated Page 4
Install Git
29 August 2020 12:53
Git-GitHub-Consolidated Page 5
Initialize Git folder
29 August 2020 13:13
Git-GitHub-Consolidated Page 6
Commits are snapshots of a point in time or points of interest
along the timeline of a project's history.
Git-GitHub-Consolidated Page 7
//Keep the commit atomic & give appropriate message
//should be single set of change-could be one or more files
Git-GitHub-Consolidated Page 8
//Every commit new snapshot is made
Git-GitHub-Consolidated Page 9
//If they are not related ,it is not good to commit together
//stage it and commit separately
Git-GitHub-Consolidated Page 10
//modifying a file
Git-GitHub-Consolidated Page 11
//got overwritten by accident
//restoring
//git rm
//to remove file(s) from staged area
//be careful with arguments
Git-GitHub-Consolidated Page 12
//you added both by mistake
Git-GitHub-Consolidated Page 13
Git Log
29 August 2020 16:28
Git-GitHub-Consolidated Page 14
Git-GitHub-Consolidated Page 15
Git Branch
29 August 2020 23:24
Git-GitHub-Consolidated Page 16
Head is where you are currently in Git
Repository
Note : Any changes in a branch is reflected in other branch also when it added but commit takes a
separate snapshot
Git-GitHub-Consolidated Page 17
Git Merge //set vim as core editor in ubuntu
21 August 2020 14:55 //useful if you set to something else and is not working
Git-GitHub-Consolidated Page 18
Fastforward merge-when branch (non master) is
committed more than once and master is not changed.
Simple merge will work from master
No Fastforward merge- when master has 1 or more
commits and the non master branch does not know it
has its new commit . We have to use
--no-ff option
Git-GitHub-Consolidated Page 19
Rebasing
31 August 2020 01:03
Git-GitHub-Consolidated Page 20
//new merge commit happens
Git-GitHub-Consolidated Page 21
Git-GitHub-Consolidated Page 22
//we are basically putting one branch on top of other one
Git-GitHub-Consolidated Page 23
//interactive rebase
//remember to squash the commits
Git-GitHub-Consolidated Page 24
Remote Repository
30 August 2020 00:36
//after push
Git-GitHub-Consolidated Page 25
//below is the case where lot of commits have happened but not set to remote
//repository & remote repository files and local master does not match
//so if we try to push ,it will not work
//
//if we want to push to remote first set the upstream and branch name
Git-GitHub-Consolidated Page 26
//if we want to push to remote first set the upstream and branch name
//sometimes it may not work, if there content in the local repo & remote repo does not match
//then we have to pull from remote & then push
//this can happen if remote master is merged from another branch in remote and we
//don’t have the changes
//suppose if the commits does not match because of different repositories we have to use
//--allow-unrelated-repositories
//git hub does not allow to raise pull request from remote if the branch histories are different
//solution is pull from remote branch ,merge here and update the master directly
Or
Git-GitHub-Consolidated Page 27
Pull Request
30 August 2020 01:14
2. Rakesh has to create login to his github account & create a pull request
3.
4.
Git-GitHub-Consolidated Page 28
6.
8.
9.
10.
Git-GitHub-Consolidated Page 29
Fetching & Pulling
30 August 2020 02:17
Or
Git-GitHub-Consolidated Page 30
Git-GitHub-Consolidated Page 31
Cloning & Forking
30 August 2020 22:16
//when you clone, Repository Name RakeshVijay will become folder and the repo
//contents will be inside the RakeshVijay folder
//we have to shift to the RakeshVijay folder in order to access and Work on it
//we can also achieve the same with downloading the zip and unzipping in the location we wish to work
Forking
Forking is done to make a separate copy of the repository which we would not likely to merge it back
//eg some publicly available projects ex linux
//we can also contribute to the open source project, make changes in your copy & push it to your branch and generate pull request. If they agree
//with your code ,it will be merged
Git-GitHub-Consolidated Page 32
Git-GitHub-Consolidated Page 33
Merge Conflict
30 August 2020 22:56
1. When a merge conflict occurs, open the file remove what is not required & keep what is required
2. Add the file git add filename(s)
3. git commit
4. Git merge
5.
6.
7.
Git-GitHub-Consolidated Page 34
Cherry Picking
31 August 2020 11:41
Git-GitHub-Consolidated Page 35
Git-GitHub-Consolidated Page 36
Undoing
30 August 2020 02:55
Git-GitHub-Consolidated Page 37
//unstaging
//git clean deletes the untracked files present in the working directory
//Note: Revert will delete the changes (any file added in the commit will be deleted)
//it will not be available in the staging as it is already committed
//it will keep the changes in git history
Git-GitHub-Consolidated Page 38
//hard reset , you will loose the contents committed if reset
//soft reset, the contents of the commit will be in the staging area
Git-GitHub-Consolidated Page 39
Git CheatSheet1
14 August 2020 14:30
Git-GitHub-Consolidated Page 40
Git-GitHub-Consolidated Page 41
Git Cheat Sheet2
31 August 2020 02:40
Git-GitHub-Consolidated Page 42
Password Solution
17 August 2020 19:12
Git-GitHub-Consolidated Page 43
Git Stash
01 September 2020 01:38
Git-GitHub-Consolidated Page 44
//to see the content of the stash
Git-GitHub-Consolidated Page 45
Reflog
01 September 2020 01:46
//if we made a mistake, we can undo this by resetting HEAD based on the information
//from the reflog
Git-GitHub-Consolidated Page 46
GitEclipse
24 May 2020 00:29
Git-GitHub-Consolidated Page 47
3.Click Apply & Close
4.Creating a git Open the Project(java/maven)-> Right click on the Project ->Team-> Share Project
2.Click Next
Git-GitHub-Consolidated Page 48
3.From GitHub repository copy the .git url
6.Pushing changes Note: Don’t push directly to master branch unless you are sure
1.Before pushing your code pull from remote master to local master
to Git Hub 2.
Git-GitHub-Consolidated Page 49
This will reflect in Git Repositories(shows the change in the remote master)
3.click on Merge
5.Click Merge (Local Master will get updated from Remote Master)
8.Working with 1.Switch to local branch you want to work with (typically you will work with the branch)
2.
branches
5.
Git-GitHub-Consolidated Page 50
7.Work with the branch ,add files,
1.When you create a new file or modify an existing file, after saving it will come to unstaged/tracked
2.Click on add file/files to index which will become Staged
7.Once the work over /milestone reached ,right click on the branch
8.
9.Click Preview
Git-GitHub-Consolidated Page 51