(tentative) Name the most important thing you learned yesterday
git commit -p:+1:
git diff. :+1:
git commit -p. Also the difference between
git commit -pand
git diff --staged. Excellent pedagogically organized material
HEADwas mentioned briefly at the end (the casette tape analogy) but indeed this question perhaps arrives too early. I am noting these good points as issues so that we follow up: https://github.com/coderefinery/git-intro/issues/267 and https://github.com/coderefinery/git-intro/issues/268
--orphanbranches, where the first commit of the branch has no parent:
git branch --orphan somename
git addboth files, then
HEADis our current position, in analogy of the recorder head for those who remember casette tapes. when we switch branches with
git checkout somebranchor
git switch somebranch, then
HEADmoves over to that place.
HEADtypically points to a branch (and a branch is like a sticky note pointing to a commit hash). But
HEADcan also point directly to a commit hash and in the latter case we have a “detached HEAD” state.
What to do
Solution of the above ex:
git config --global alias.graph "log --all --graph --decorate --oneline"
git branch experiment master
git checkout experiment
git graphalias is defined and works
git graph should produce a graph similar to the picture in this exercise
experimentafter committing changes to
git graphalias should show the whole tree. If the tree is big you can scroll it with arrow keys,
qreturns to your command line.
git graph, but gitk allows to visualize longer trees in a GUI so I was wondering if there is patch to visalize it with all branches and not only the current one. git graph is awesome, but having a GUI is also good sometimes
git branch new-branch 2e70ce4)?
git branch -dor
git branch --deleteif the commits have not been merged to another branch.
git branch -D
Merging branches on your own until: XX:22
pushand then delete the branch?
git remote add origin someurl; git push origin thatonebranch. Then you have a new repo and only that branch in there with all commits on that branch. And after that, indeed you can delete the branch on that original repository.
masterof the remote. Then you can clone the new repo anew and delete the cutaway branch in the original repo. This can get messy, since we’re used to have only one remote, and remote branches to be named exactly as they are locally.
cp -rthe repository folder to a new folder and you delete the branch in one and delete all other branches in the other.
diffdoes not work, in the context of merging commits? Will it just check the checksum and report a conflict if the files are different? Or are there some useful tools for non-text files?
masterin two different ways before that merge. only after we have merged
like-cilantrowe have a modification of that line on
masterand the second merge will conflict. Please let me know if this explanation was not helpful enough and we expand.
like-cilantroversion over the
experimentare topologically not ordered but happened “in parallel”. In this case Git does not take the later change in terms of time stamp but it compares whether they are related in terms of “ancestry”. Please do not hesitate to raise this issue if it is not clear or not well explained.
Create two branches as the instructor showed
Ask for help if you need it on the chat or here
error: Merging is not possible because you have unmerged files.hint: Fix them up in the work tree, and then use 'git add/rm <file>'hint: as appropriate to mark resolution and make a commit. fatal: Exiting because of an unresolved conflict.
git add somefiles. In other words we signal conflict resolution by staging the change. From the error I guess the staging did not happen?
git reset --harddon’t we lose the changes introduced in the commit?
git reset --hardmoves the branch to a commit in the past. But the commits are still there and they are now reachable via the newly created branch.
git reset --hard somehashbefore “saving” the commits to a new branch, I will have a hard time finding these commits again. In fact they have not been deleted and I can recover them with the help of
git reflogwhich keeps a log of all commits you have visited, for some time.
git add. You can then type
git commitand you will have a pre-filled commit message
masterfor the name of the master branch. It is possible to change it in the personal settings of your account in the “Repositories” tab, and restore the default to master for new repositories.
masterbut now GitHub defaults to
git remote -vinitially would be good idea before adding the remote link
fatal: remote origin already exists.
git remote add ...with a remote already defined. You can remove the remote with
git remote rm originand then try again and it will work.
originis a placeholder and we will explain tomorrow what this really means. :ok_hand:
myusernamewith your github username). This way, nobody can write you to that address but GitHub will still be able to count your contributions.
git logso if you don’t want your email address to become visible at any point for nobody, you can use the above answer.
git config --global email@example.com(replace “gitusername”)
git remote -v
git remote rm origin(this removes the “origin” placeholder)
git remote -v
git remote add origin ...
firstname.lastname@example.org: Permission denied (publickey). fatal: Could not read from remote repository.
What is most likely wrong?
masterthat is used in branch
abut altered in branch
b, these three branches can be merged without conflict but it will cause erroneous behavior, won’t it? Because the usage of
adiffers from its implementation in branch
b(and hence in the merged
git branch -M main. We have done that because recenly GitHub started calling the default branch “main”. This setting can be changed. It’s also good to see that there is nothing really special about “master” or “main”, they are just names and can be renamed.
git log -Slook? Only in the commit Messages?
git log --oneline
mostly depends on your preference I guess, but Gitbash is probably somewhat easier for Git and has unix commands
git graphfor example will become huge pretty large. Love VisualStudio code with a linux shell.
git checkout -b new_branch master is just a shorthand to
git branch new_branch master and
git checkout new_branch. So nothing really new, but I believe we have not seen it before
git annotateis extremely useful
git grepgave no output at all?
git grep somepattern(where somepattern is the text you search for)
C:\Users\XXXX\recipe\recipe-branching\rvest>git grep 'No links matched that expression' fatal: ambiguous argument 'links': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'
try with double quotes? error looks like that git thinks “links” is a file.
R/session.R: stop("No links matched that expression", call. = FALSE)
git bisect, what should we do if at a given commit we don’t know if it is good or bad? Is there a way to tell git “I don’t know, give me the next/previous commit” ?
git bisect skipthat version.
test.pyand after defining the search endpoints, I ran:
git bisect run python test.pyand it located the bad commit. I suggest we look at it together via screenshare?
Please give us feedback for today: one thing that you enjoyed, one thing we should change/improve:
ensure some time to discuss the interesting discussion questions on the webpage of the course programme :+1:. I’m wondering about many of them. e.g. “Discuss how Git handles conflicts compared to the Google Drive”
git pusheverything is only your local computer.
:::info Always ask questions at the very bottom of this document, right above this. Switch to view mode if you are only watching.
We are monitoring this hackMD, but we will reply every now and then so that you can focus on the speaker. :::