To find questions and answers from yesterday, please follow link above
RB: Oh no, did we forget to mention tags?
Sorry for this question but I guess I missed sth. So these changes/merges/branches are local. How to sync with local and web? Is it possible? I mean when I create a project from terminal, may I have an ability to modify from web interface or vice versa?
https://coderefinery.github.io/git-intro/remotes/
From twitch: for this random question, but I tried to learn git from different ressouces, but I think the best way is to learn while working on big projects, but unfortunately its not a given to be a part of big projects for beginners, what do you think?
Is using GitHub for sharing and synchronizing the codes across the machines good practice? Not for version controling?
Is creating a private git repository on the web safe?
Are GitHub and GitLab similar and how to choose where to store your projects?
Can one use GitHub not only for code but also to collaboratively work on datasets? To share with colleagues and multiple people modifying it.
A third authotication method would be using Personal access tokens right? Is there like a tier list for access methods?
Can I use my own recipe repository even though I didn't quite finish yesterday?
I am bit confused, weren't we creating online github repository (recipe) yesterday ?
:::info
https://coderefinery.github.io/git-intro/remotes/#authenticating-to-github-ssh-or-https
Exercise feedback:
:::info
https://coderefinery.github.io/git-intro/remotes/#authenticating-to-github-ssh-or-https
Exercise feedback:
After setting up an ssh token for gitlab, the command ssh -T git@gitlab.com works in command prompt, but it does not work in git bash. EDIT: turns out bash home is set to a university remote drive, so its looking for the key in the wrong place I think. changing the home variable to the proper drive doesn't seem to work though and it resets after rebooting. So anyway to change the bash home variable permanently? (I tried export HOME=/c/users/me, but this doesn't help at first and it switches back to a different drive on reboot)
When we create the remote on command line, does it become public or private on github?
Could you explain these lines a bit more: Add a remote reference with the name “origin”, Rename current branch to “main”, Push branch “main” to “origin”? Specifically, what is meant by "remote reference" and why did we have to rename the branch if it was already called main (from yesterday)?
git remote add origin git@github.com:USER/recipe.git
. Explanation: remote is a git repository somewhere else, behind some web address. in this case the web address is the github address. "origin" is a name to that address. then from here on we can refer to "origin" and git will know we mean github.All went well, but now I ask myself whether by cloning the recipe folder locally I will be able to see my change history from yesterday. In other words is the info in .git
also pushed on GitHUb and can been seen/cloned?
like-cilantro
and there is a new branch in my online version. Ok, so I guess this is the reason. Can one push all branches at once? Like the whole project on the local machine?
push --all
(all branches). after that you should see identical histories.After pushing the repository to github all branches are gone in the online version. I am only left with the main branch.
push
by default only pushes the branch you say - the remote wont' have the others. Unless you push them, which is also normal to do if you want.
I cloned your repository despite having a local one. Now I am getting an error message when I try to push. How can I resolve this?
What is the difference between SSH and HTTPS? I there a preferable one to use?
Can I think of origin as the remotes HEAD, or what is origin?
Where can I see the history on Github, similar to if I type "git graph"? It seems like now all of the history is gone.
I find some parts confusing when setting a remote repo.
git branch -M main
why do I need o create a new branch called main? I already have the main branch locally. git push -u origin main
"u" indicates upstream according to the documentation, what does that mean? And why am I pushing from origin to main, shouldn't it be the other way around?-u
means: create a correspondence between the two branches so that next time you push this branch, it's enough you type git push
instead of git push -u origin main
.
Do you always call it "origin"? in this part: Add a remote reference with the name “origin”
I accidentally cloned my repository to the wrong folder. Can I move it somehow?
mv
moves it. If you can find it by the file browser on your computer, that works too (and is probably simpler)SSH keys. I had to remove the deploy keys from yesterday's and add to the new. Any way to do it more elegantly?
As I was pushing from github online to my local version I received following error:
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'github.com:USER/recipe.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
If I want to clone the repository with this command: $ git clone git@github.com:USER/recipe.git
, should I be at the main directory or in the recipe directory?
Can you explain the aim of setting an SSH key? (Sorry for this silly question). Months ago I set it for my UiO Git account. When I tried to run the command ssh -T for my personal Git account
(because I do the exercises on my personal account), it asks me to write:
Enter passphrase for key '/Users/myusername/.ssh/id_rsa':
I wrote and
Hi USERNAME! You've successfully authenticated, …
What did I do during this process :))
ssh -T
is used for testing in this case. So you just tested that you can log in.Why do we run git branch -M main
?
Why are we calling 'repository'? and not just 'local' or 'remote' folders or projects? Do we mean some specific meaning to emphasize?
So "push" and "pull" basically just means uploading and downloading to/from GitHub?
On GitLab I can use git push --set-upstream git@gitlab.com:username/repo_name.git main
to create a repository named repo_name without needing to create it manually like we do in the exercise. Is this a gitlab specific thing?
push
.I get the following error, after the push command (git push -u origin main
)
ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
git remote add
command correct?git remote add origin git@github.com:USER/recipe.git
(with the correct USER), which gives back: error: remote origin already exists.
Is 'origin' an arbitrary name that we can change or is it Github-specific?
It would make more sense to have git push [source] [target]..., right?
I get this error git: 'graph' is not a git command. See 'git --help'.
git config --global alias.graph "log --all --graph --decorate --oneline"
+1Where was the insights part in Github where you saw a graphical display of the branches?
When I pull from remote repository to update my local repository, if my local file A is different from the remote file A, will it be merged or overwrite, or will it give me a conflict message?
git pull
, we always also implicitly merge. Most of the time there won't be a conflict. if the same portion was modified differently locally and on remote, there will be a conflict during the git pull
step (git pull
is git fetch
followed by git merge
; we did not explain that yet -> tomorrow)what if I merge a branch into the main branch and then I realize I shouldnt have done that. Can I still go back to the version that they were not merged? In that case what will happen to the other mergings and progressions that I made later on (after the wrong merging)?
git log
.git reset --hard HASH
. git revert
and one can revert also merge commits. the difference between revert
and reset
is that the first adds a new commit that undoes something that happened previously, the latter modifies history. morale of the story: use git revert
if you need to undo something that other people already depend on since git revert
will not change the history in the past for other people.I deleted a branch yesterday. It is not on the github web now, clearly. Is it still possible to restore it?
git branch BRANCHNAME HASH
(where HASH is the identifier of the commit where you want your branch to point to)git reflog
(we did not explain or show reflog at all)Why do we only see the main branch in the remote? Where are the other branches we created yesterday?
git push --all origin
Instead of doing git remote add origin git@github.com:USER/recipe.git
and ‘git push -u origin main’ could you also do git push -u git@github.com:USER/recipe.git main
? Or do you need to define the address as something remote?
Is there a way of enabling ctrl+v
in your terminal?
ctrl+shift+v
works.Wow, good idea, is there a hotkey for Windows as well ? (copy paste hotkey)
Ctrl+C
for copy and Ctrl+V
for pasteSorry, I wasn't clear. I meant a way to use copy paste inside the git bash terminal
ctrl+shift+c
and ctrl+shift+v
Nice trick! +1 (My only challenge is that I cannot use shift + arrows to highlight. But it is indeed neat to be able to copy and paste!)
:::info
:::
https://coderefinery.github.io/git-intro/archaeology/
the grep -i fixme
command is taking forever for me, can I exit from it?
grep -r -i 'fixme'
, things will work out using default grep (non-git) as well. But I assume it depends as you might have no grep availlable in your terminal.Can we create a branch from a tagged version instead of a committed version?
HASH
can actually be anything that identifies a version.:::info
https://coderefinery.github.io/git-intro/archaeology/#exercise-basic-archaeology-commands
Status:
How can we find the HASH for older brances?
git log branch_name
should show the commits in that branchI accidently cloned the new repository to the recipe folder, can I just remove it and then clone it again to the upper folder?
I have an unrelated question: I have a meeting tomorrow from 10-11. Would you still recommend that I join the workshop tomorrow? I am a "individual learner"
I wonder whether the command "git annotate ...py" would also work for Jupyter notebooks?
git annote
would show you the actual text file. So it works, but it's not the same.If I want to make all my directories in a folder called git, how should I make this folder and make sure the new directory is within this folder?
mkdir git
cd git
git clone ...
(which will create a new subfolder under your "git" folder)If my git bash does not use less
for scrolling long outputs, how can I activate it?
git config --global core.pager less
but I haven't tested thisAny idea how to do a search using Git Bash in Windows on its own command output. I tried to print the log using the git annotate function on threshold.py and it gives a lot of things ?
git annotate SOMEFILE | grep SOMETEXT
(this will run "git annotate" on a file and then in that output, in one step, you can search for SOMETEXT)I created the branch past-code
(90544b4fa)and then the one just-before
(90544b4fa~1). Then I switched to the just-before
. Now here I was not expecting to see commit 90544b4fa as in the timeline I have in mind it did not happen yet. What I am thinking wrong?
90544b4fa~1
means "commit right before 90544" - so 90544 isn't in it's (past) timeline anymore. There's no easy shortcut to do "commit right after this one".1318 git branch past-code 90544b4fa
1319 git status
1320 git switch past-code
1321 git show 90544b4fa5
1322 git switch --create just-before 90544b4fa~1
1323 git status
1324 git show 90544b4fa5
1325 git status
90544
on top of git log --oneline
but git show 90544
will still work. git show
can point to any commit in the repository. it does not have to be older than the current branch. Did this explain the question?
git log --oneline
- it was a very good questiongit log --oneline | grep "90544b4fa5"
is empty.In the bisect exercise, I got the following error:
Some good revs are not ancestors of the bad rev. git bisect cannot work properly in this case. Maybe you mistook good and bad revs? My good was the first commit and bad the latest.
In "Exercise: Basic archaeology commands" I do the following:
git config --global core.pager less"
(from question 52, 58). After this the search worked.After I inspected the code as it was before the mistake was done by using 4dff462e52~1, is it possible to continue working with this version? Should I merge the just-before branch to the main branch? Or is it just for the sake of inspecting and then correcting manually?
restore
that file to its old version (git switch main, git restore old-version filename
).I tried git config --global core.pager less
and now I'm stuck in that view (running annotate). How do I get out? Enter produces more lines and esc and ctrl+x don't work. I'm using Git Bash on Windows.
If I do git restore old-version filename
will I lose all the versions after this old version? Or what does git restore
do exactly?
Would git log -S "TEXT HERE"
also work to find the commit where a specific line was deleted?
Could you show how bisect
works in practice?
git bisect good f0ea950
(the one in the example) doesn't workgit bisect reset
presumably?) Can we pipe grep in less command?
/
searches (n
/ N
to to next/prev)&
will limit to matching linesgit show HASH | grep "keyword"
is it possible?Can y'all correct answer to 52.?
:::info
:::
Where can I find the "cheatsheet"?
Throwback to the push exercise: when I try to push it asks for username and password, and when i put it in i get this:
mic/win/linux? - tried ssh. Im on mac. After 'git push -u origin main' it asks for username and then password for https://github.com > got this issue too. If you have a key (or create a new one) it has to be called id_rsa.pub or id_ed25519.pub (there is a third one). It does not recognize any other key names. You also need to a) add the key to your user profile (didn't work for me) or as a deploy key to your repo (this did). And b) do all the stuff with the agent, etc or eventually creating a key -> https://docs.github.com/en/authentication/connecting-to-github-with-ssh/using-ssh-agent-forwarding).
https://coderefinery.github.io/git-intro/recovering/
We can all start from this repository:
Regarding (computer) directory structure, do you recommend having one git directory in which one places all git-tracked projects?
What is a staged change ? (I forgot)
git add
), but not committed yet (git commit
)
git add
stages/prepares the change to be committed. it is a nice way to prepare changes and make sure to collect changes to nice logical units if you have many modifications in your working area.how do you selecet where to restore with -p?
Can we 'revert' to a commit that is not the HEAD? If yes, what about the future commits?
Can you demonstrate how to combine many commits in one commit?
git reset --soft HASH
to the HASH just before the oldest commit to be squashed. This will "remove" commits but keep your changes and stage them. Then you can commit them all in one commit.git rebase -i HASH
where HASH is a bit more in the past than what you want to edit. it will open an interactive menu where you can do all these things. it's fun but experiment first on a test repo, not on your real code since rebase modifies history. git branch backup
. If I mess up and all is destroyed, I can go back to that backup branch and all my commits are still there.
I have fixed a change in ingredients.txt and entered git add ingredients.txt
. When I enter git commit --ammend
I get the prompt You asked to ammend the most recent commit, but doing so would make it empty
.
git revert
in this scenario?
git add
again, then git commit
.:::info
https://coderefinery.github.io/git-intro/recovering/#exercise-revert-a-commit
What is origin/main in my case?: 40d63a5 (HEAD -> main, origin/main) Merge branch 'dislike-cilantro' Decided on half of the spoon
main
on origin and origin is the place we cloned from. Tomorrow (Thu) we will clarify these in more detail. but already at this point I can say that when we clone from a place, Git defines "origin" to refer to that place and it creates a local branch from the default branch (in this case "main") and it creates a read-only reference to origin/main ("main" on origin). If too confusing, tomorrow it will become clear.I am getting the error "commit XXX is a merge but no -m option was given. fatal: revert aborted." after having committed a change in ingredients.txt.
git graph
). you can revert a merge commit with git revert -m HASH
(where HASH is the commit identifier)Why do I have a red (origin/main) tag in my git graph? And then also a (HEAD->main) as the top-most tag.
git remote -v
will list some details.Does the order matter with git add and git commit?
I am not getting a good understanding of a difference between commit and push. I have 2 local commits and now he is asking me to push.
git commit
, it adds a new commit to the stored history. In this case, you also have a remote repository on GitHub. git push
will upload your commit history to that online repository.In which case it's more interesting to use reset
instead of revert
or create a branch starting from a previous commit ?
revert
becomes interesting if other people already cloned that commit and add new commits based on the branch that I have published. Now if I delete it or change the branch, it will be surprising and confusing to others. Did it clarify?revert
also just for me for those situations.Yes sorry, I made a mistake in my question. It's reset
that seems surprising since the 2 other solutions seem better.
reset
and revert
will not be enoughWhy it asks me to push when I try 'git commit --amend', but it does not when I do a simple commit ?
"On branch main
Your branch is ahead of 'origin/main' by 3 commits.
(use "git push" to publish your local commits)
No changes
--allow-empty
, or you can remove the commit entirely with git reset HEAD^
.HERE is now something missing due to a weird multi-cursor editing glitch in HackMD archive. Sorry about that! -MJ ps. always keep backups of your stuff you are editing, or better yet: a version control 🙈
No changes.
[main bd26dca] going back to less avocado
1 file changed, 1 insertion(+), 1 deletion(-)"
Is amending only for editing the text in the previous commit message? Or does it also revert the previous changes, like with git revert?
git add
:ed)A curious question. If the branch does not take space, how does it behave in the memory? If it is not a physical copy then how is it done?
There is git pull but there is also git fetch whats the diff?
Can you demonstrate any example of using GitHub for version control when writing your thesis? Eg working in word and commiting to Git, is that possible?
:::info
Then the general Q&A below. :::
https://coderefinery.github.io/git-intro/level/
"+1" the questions you'd especially like discussed
How will we get connected to participants to collaborate with tomorrow? Asking as an individual participant (who is sometimes out of office during this workshop).
Do most people who use git actually use git bash or any other terminal-window or do they use github desktop or visual studio code's git-add-on or other programs for git?
How do I push changes following a reset to the remote, if I had already pushed the changes I am reverting with the reset?
git push --force origin SOMEBRANCH
It seems really that understanding a git history of a project that you just want to start collaborate in is very complicated. How is it possible to collaborate in opensource projects? Is it even reasonable and if yes, what level of expertise in git is needed? +1
Is git commit -p
per file or per line? And, if it is per file, why do not we just usegit add
the selected files?
How was the learning curve for you before starting using Git? How did you learn it? and at which point you decided you had to learn it?
So, I have a project with already 60 scripts in there. I have the feeling is important for me to keep track of the next changes. How would I recomment I incorporate git in this already big project? Thanks
git init
and see content through git status
. Stage and commit all or in chunks and include reasonable files to .gitignore. Then push to GitHub/GitLab and continue git workflow with reasonable size commits + consier using branches when trying new stuff.What plugin/library/... would you recomend to use git, when your main programming language is R and Rstudio as a tool to use? +3
How do you decide what to push to git? What kind of things do you look for on github (or in what instances woudl you look for other peoples' code?) ((person w very non-technical background asking))
How do you go about finding the right commands? Sometimes I feel overwelmed by the man pages in git/linux or just forget the exact command
tldr git push
it will give me short and nice summary of commands that I can use without too much textIt is advised to not track binary files. Another curious question. Why not(in brief)?
Question 90. but with Python?
Let's say I have file.txt
and I add and commit and then I add the .gitignore
file. And then I add the file.txt
in gitignore. How would I untrack it?
git add
git restore --staged
Just a general question, as an expert in git and also probably fluent in a couple of programming languages, how often do you need to actually look things up? do you still do mistakes?
git COMMAND --help
to check or review help pages when doing something I don't do often - always good to check! For complex stuff always web search + stackoverflow - even now.add
, commit
, pull
or push
, I check before running.So if I want to add the tracked file in gitignore, I have to untrack it first and then add to gitignore to ignore it. Am I right?
Would we learn about .gitignore
in the future sessions?
status
ignore files in there that aren't already tracked.What is the difference between merge and rebase and why would I use one or the other?