You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 1. Filter the commit loggitlog# displays list of commitsgitlog--oneline# displays a list of commits in a linegitlog-3# displays the last 3 commitsgitlog--since=2019-04-13# displays commits since dategitlog--until="3 days ago"# display commits until gitlog--after="2 weeks"--before="3 days"gitlog--author="Kevin"# displays Kevin commitsgitlog--author="Sally"# displays Sally commitsgitlog--grep='Initial commit'gitlogb447401938..HEADgitlogexplore.html# display commits of a particular file# 2. Format the commit loggitlog-p# patch the change betweengitlog--stat# shows statistics of what has changed# Log formatgitlog--format=short# format the commit loggitlog--format=mediumgitlog--format=onelinegitlog--oneline# shortens the SHAgitlog--graphgitlog--graph--all--oneline--decorate
Setting up local repository on remote
cdproject_namecat .git/config# check for remote URL''' [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = REPLACE_WITH_YOUR_URL fetch = +refs/heads/*:refs/remotes/origin/* '''# Change remote url with username urlgitremoteorigin# Remove origingitremotermorigin# Add remote urlgitremoteaddoriginhttps://github.com/username/demo_repo.git# Add feature_branch to remote urlgitpushoriginmaster# First version# To create & track new feature branchesgitbranch*mastergitcheckout-bfeature_branch_1gitpush-uoriginfeature_branch_1# add & track feature_branch_1 to remote gitbranch*feature_branch_1mastergitcheckoutmastergitbranch*masterfeature_branch_1gitcheckout-bfeature_branch_2gitpush-uoriginfeature_branch_2# add & track feature_branch_2 to remotegitbranchfeature_branch_1*feature_branch_2mastercat .git/config# check if the new feauture branches are tracked''' [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = https://github.com/username/demo_repo.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [branch "feature_branch_1"] remote = origin merge = refs/heads/feature_branch_1 [branch "feature_branch_2"] remote = origin merge = refs/heads/feature_branch_2 '''# To untrack remote branchesgitbranch--unset-upstreamfeature_branch_1gitbranch--unset-upstreamfeature_branch_2# Second version# To create & track new feature branchesgitbranch*mastergitbranch-uorigin/mastermastergitbranch-uorigin/feature_branch_1feature_branch_1gitbranch-uorigin/feature_branch_2feature_branch_2gitpushoriginmastergitpushoriginfeature_branch_1gitpushoriginfeature_branch_2cat .git/config# check if the new feauture branches are tracked# To untrack remote branchesgitbranch--unset-upstreamfeature_branch_1gitbranch--unset-upstreamfeature_branch_2
Check Remote Branches
gitbranch-r# show remote branchesorigin/mastergitbranch-a# show all branchesls-la .git/refs/remotescat .git/refs/origin/remotes/origincat .git/refs/origin/remotes/origin/remote
gitbranch*mastergitcheckout-bnew_featuregitbranchmaster*new_feature# Make changes to a file (e.g. mission.html)# stage filegitaddmission.html# unstage file gitresetHEADmission.html
Track Changes
gitbranch*masternew_featuregitcheckoutnew_featuregitbranchmaster*new_feature# Make changes to a file (e.g. mission.html)gitstatusgitcommit-am"Change title in mission page"gitstatus# Message: "Nothing to commit"
Stash Changes
gitbranch*masterreset_branchseo_titleshorten_titletext_editsgitcheckoutshorten_titlemasterreset_branchseo_title*shorten_titletext_edits# Make changes to a file (e.g. mission.html) gitstatus# modified: mission.htmlgitcheckoutmaster# Message: "Error, please commit your changes or stash them before you switch branches"gitstashsave"changed mission page title"gitstatus# Message: "Nothing to commit, working tree"# View stashed changesgitstashlist# "changed mission page title"gitstashshowstash@{id}
# Retrieve stashed changesgitstashlistgitstashapply# Delete stashed changesgitstashlist# list stashesgitstashsave"Delete me"# saves new stashgitstashlist# list stashesgitstashdropstash@{id}
gitstashclean# clean everythinggitstashpop# removes the stash
Remove Last Commit
gitresetHEAD^# remove commit locallygitpushorigin+HEAD# force-push the new HEAD commit
gitbranch*masternew_featureshorten_title# Compare master with new_featuregitdiffmaster..new_feature# Compare master with shorten_titlegitdiffmaster..shorten_title# Compare new_feature with shorten_titlegitdiffnew_feature..shorten_title# Compare and show color changesgitdiff--color-wordsnew_feature..shorten_title
Merge Branches
gitbranchmasternew_feature*reset_branchseo_titlegitcheckoutmaster# Bring changes from seo_title into mastergitdiffmaster..seo_titlegitmergeseo_titlegitdiffmaster..seo_titlegitbranch--merged# check merged branchesgitbranch--no-merged# check not merged branches
Merge Conflicts
# Solution:# * abort merge# * resolve the conflicts manually# * use a merge tool# To resolve the conflicts manuallygitbranch*masterreset_branchseo_titleshorten_title# Resolve conflicts for text_edits with master branchgitcheckout-btext_editsgitbranchmasterreset_branchseo_titleshorten_title*text_edits# Make change in one file (e.g. mission.html)gitcommit-am"Text edits to mission page"gitlog--oneline-5gitlogtext_edits--oneline-5gitcheckoutmaster# Make a change in master to the same mission.html pagegitcommit-am"Replaces straight quotes with curly quotes"gitlogtext_edits--oneline-5gitbranch*masterreset_branchseo_titleshorten_titletext_editsgitmergetext_edits# Message: Error, merge conflict in mission.html gitstatus# Solutions:# 1) abort the operationgitmerge--abort# 2) merge conflict : fix commits -> rename Git tags and keep the right textgitdiff--color-wordsmaster..text_editsgitaddmission.htmlgitstatusgitcommitgitmergetext_editsgitlog--graph--all--oneline--decorate# Strategies to reduce conflicts:# * keep lines short# * keep commits small & focused# * merge often# * track changes to master