Wojciech Hardy
link: https://hackmd.io/@WHardy/RR25-git2
git init --bare
to create barebones for a central repository (with no initial commits)
git clone [repo_name] [clone_name]
to create a linked copy of the repo_name
repository.
git fetch
grab information about new commits/branches from the central repository.
git pull
to grab the (new) commits from the central repository to our repository.
git push
to put our (newly created) commits in the central repository.
We're going to pretend we have two developers and a central repository.
In our workspace, let's create a new folder RR_git2 and go inside
Let's create a repository named RecapRepo and go inside
Change local user.name to "RecapRepoUser"
In RR_git2 create a clone of the first repository; go inside
View the contents; check the status
View the config
file in the .git
folder.
(e.g. in notepad)
We're now going to pretend we have two people collaborating, using a central repository to manage the workflow.
(Remember to use the appropriate option when initiating the repository!)
cd RR_git2
git init --bare CentralRepo
git clone CentralRepo Dev1
git clone CentralRepo Dev2
user.name
for Dev1 repository to "Developer_1"cd Dev1
git config --local user.name "Developer_1"
user.name
for Dev2 repository to "Developer_2"cd ../Dev2
git config --local user.name "Developer_2"
We'll be imitating this:
upstream
echo "This will be the file with code" > code.R
git add .
git commit -m "Added the file with code"
git status
git push
git status
git pull
As you go, try to remember what are the states of the Dev1, the Dev2 and the Central Repositories at each step. (You can even draw them)
cd ../Dev1
touch readme.txt
git add .
git commit -m "Added readme.txt"
git push
cd ../Dev2
git status
git status
git status
.git fetch
git status
git pull
ls
echo "second line of text" >> readme.txt
touch readme.md
git add .
git commit -m "Added readme.md and changed readme.txt"
git push
cd ../Dev1
echo "A line added by Dev1" > text3.txt
git add .
git commit -m "Added text3"
git push
Follow the instructions from Git to resolve merge conflicts.
In Exercise 6 we had a divergence, but without a conflict (commits differed, but there were no conflicting changes to files).
What if two devs make two different versions of a file?
We're in a merging mode. We can edit the file (e.g. in Notepad) to figure out what should remain. Then stage it and commit it.
The merge becomes a new commit (try git log
)
While still in your Dev2 repository, run these three commands:
git status
> git2_a.txt
git log
>> git2_a.txt
git ls-files
>> git2_a.txt
Send me the notepad file git2_a.txt (wojciechhardy@uw.edu.pl).
If you forgot about adding a message to your commit, you might have ended up in VIM. It's a free, text-editting software that sometimes feels like a trap.
Tl;dr: hit [ESC], then type *:q
* and press Enter
.
Repeat your commit with a helpful description.
You can also try adding the comment in VIM instead, and then exit with :wq
instead, which should do the commit with the comment.
See more in this helpful Stackoverflow answer.
Read more on the three trees with the git reset
guideline
If you need more, just Google tutorials/blog posts/YouTube videos until you find one that makes it clear :) Lots to choose from!