Please remember: do not copy&paste.
-
Please create a github user.
-
Generate a personal access token that works as a password, follow the offical instructions
-
Create on your machine a directory:
mkdir learning_git cd learning_git
-
Configure your git client to attach the right infromation to the commits (replace
wojciech11
with your github user):# small L git config -l git config --global user.name "wojciech11" # we do not like spammers git config --global user.email "[email protected]" # notice, that the complete configuration is stored # in the config cat ~/.gitconfig
-
Initilize the git repository:
# check where you are pwd # initilize git init # notice # you will find the git repository in .git/ ls .git/ # you can also have your local # configuration cat .git/config
-
Create the first version of your
README.md
, please follow the guide to add sections, images, and lists. -
What is the role of
README.md
? Why is it important? -
Let's learn how to use Git. We will practice the git mantra modifing README.md and saving every version of the file git. Please do 3 iterations:
git status git add README.md git status git commit -m "My N commit" # N=1,2,3 git status git log
-
Please see how the git history looks with a visual tools:
gitk gitg
-
Please create an empty github repository
learning_git
, follow the instructions:# the right path, you will find in the github instructions git remote add origin https://.../learning_git.git # run, it will fail git push # only once, later you can just call `git push` git push --set-upstream origin master
-
Let's go back to our git mantra and add one more step
git push
:git status # modify README.md git status git add README.md # without -m, git will open a text editor # for you to provide the message git commit git log git push # refrash the browser and check whether # you see your changes there
Please do the git matra at least 3 times.
-
Too tired to copy&paste your token? You should enable the
credential.helper
:git config --global credential.helper store
Now, git will remember your token.
If you want to disable the helper, run the following commands:
git config --global --unset credential.helper rm ~/.git-credentials
-
What if I want to clone (download) my code? Let's have a short exercise that shows how to do it:
mkdir ~/tmp cd ~/tmp # url z github.com git clone https://github.com/<TWOJ_GITHUB_USER>/nauka_git
-
Draw a schema that shows how the process of adding changes to remote git repo works (in our case github).
-
Git branches? Pull request?
# equivalent of `git status` but for braches git branch git checkout -b add-documentation git branch # add two or three commits # e.g., mkdir docs touch docs/README.md # your fav editor atom docs/README.md # here comes the git commit mantra
# good to see the history # in a graphical tool gitk gitg
# let's publish our branch to github git push -u origin add-documentation
git branch # let's see what we have in our directory ls # let's change the local branch to `master` git checkout master # what did change? ls # let's come back to the branch # with documentation git checkout add-documentation ls
-
Merging:
git checkout master # let's get the changes from the add-documentation branch # on our master branch git merge add-documentation git push
Follow the instructor.
- feature branch workflow / github flow / trunk-based development
- your own with branches, e.g.,
dev
-> the dev environemnt,prod
-> production - git-flow
See also comparing workflows.
- simple: gitk, gitg; advanced: sourcetree or kraken; text-based: tig
- interesting: gitmoji-cli
- Git commit messages: semantic/conventional, imperative (cbea.ms/git-commit)
- Git style guide, e.g., https://github.com/agis/git-style-guide or https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html