Skip to content

Latest commit

 

History

History
223 lines (151 loc) · 5.34 KB

File metadata and controls

223 lines (151 loc) · 5.34 KB

EX1

Please remember: do not copy&paste.

Working with Git Basics

  1. Please create a github user.

  2. Generate a personal access token that works as a password, follow the offical instructions

  3. Create on your machine a directory:

    mkdir learning_git
    cd learning_git
  4. 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
  5. 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
  6. Create the first version of your README.md, please follow the guide to add sections, images, and lists.

  7. What is the role of README.md? Why is it important?

  8. 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
  9. Please see how the git history looks with a visual tools:

    gitk
    gitg
  10. 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
  11. 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.

  12. 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
  13. 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
  14. Draw a schema that shows how the process of adding changes to remote git repo works (in our case github).

Git branches

  1. 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
  2. Merging:

    git checkout master
    
    # let's get the changes from the add-documentation branch
    # on our master branch
    git merge add-documentation
    git push

Pull Requests / Merge Requests

Follow the instructor.

Branches and Automations

See also comparing workflows.

Tools

Additional materials