Discovery Exercise on Git for Beginners
There are many online training for git
and many docs
Question 1 : Discovering local repositories
Open a shell terminal, create a new directory, change dir into it
Verify that git command does not detect any local repository
Initialize a new local git repository
Check git repository status:
Explore the (hidden) content of the directory:
Read the .git/config file … nothing special yet
Configure your git global settings
Add Some basic Alias
Example of alias and global setting son my account
These settings can also be viewed/edited directly in text file ~/.gitconfig:
Question 2 - discovering clone remote repositories
To compare with a remote repository clone, open another shell terminal,
Read the .git/config file …
Listing all the “remote” can also be done using command line:
Question 3 - git add, git commit
Save some files, add them to git, and commit them
Add your file content to git:
Commit your files
Modify again your file
Question 4 - diff, browse history, undo local modification, compare revision, undo commit
add more commits:
See also
Do a local un-committed change:
Undo local uncommitted change:
Re-checkout file content from previous commit:
compare with (equivalent?):
Amend a commit to change it (change content files, or change comment)
Undo a commit (dangerous rewrite…)
Question 5 - branch, merge
Create a local new branch, switch to this new branch
Do some modification in branch1:
Now switch back to branch master, check no modifications from branch1 are present
Then merge changes from branch1 to this branch (master)
Repeat Same question… but do simultaneously changes on “branch1” and “master” before merging (on separate file names, so not causing conflicts)
before merge:
after merge:
Question 6 - Create your own Github account, and repository
go to https://github.com
Create an account, then create a repository “csid-exercises”
clone on your local PC your new github repository:
Question 7 - Create a github private key
Go in https://github.com settings menu
Then go in sub-section for SSH and GPG Keys
Then add it to your github account (add public key part… keep private key secret)
There is a doc at bottom of page:
Learn how to generate SSH keys
Notice you could retype your password when pushing commits to github if you don’t have your private key on a PC.
Question 8 - Commit and Push to Github
Commit and push files to your new “csid-exercises” github repository
Save the commands you typed for these exercises as a text file “csid-exercises/tp-git/tp.txt”
Also add a short description markdown file for this repo: “csid-exercises/README.md”
Setup a second local clone of the same remote repository.
Try pull/fetch/push …
Question 9 - discovering Gitkatas
Question 10 - testing merge conflict, using Gitkatas
example of a gitkatas exercise on resolving conflicts:
You have to merge branch “merge-conflict-branch1” to branch “master”, but there is a conflict on file…
You must solve it to get this result: