Git & GitHub - Practice applied knowledge

  Git  & GitHub - Key Knowledge
RELEVANT FOR  DEVELOPMENT AND DS
AVANCE LEVEL NOTES


  • Git is a versatile version control system used for tracking changes in code and collaborating with others on software projects.
  • Due to a distributed version control system, Git enables you to revert to the previous state or review the project’s history.
  • GitHub is one of the most popular web-hosted services for Git repositories.
  • Repositories are storage structures that store documents, including application source code, and enable contributors to track and maintain version control.
  • Git repository model
  • Primarily focused on tracking source code during development.
  • Contains elements to coordinate among programmers, track changes, and support non-linear workflows.
  •  Repositories are storage structures that hold code and track version history using Git; platforms like GitHub extend these repositories with additional features such as issue tracking and collaboration tools.
  • GitHub enables you to create repositories, edit files using the web interface, commit the changes to the file, upload the files, and a lot more.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
github.com
create an accounnt
upload files
commit changes
 
 
Generate access token
Github acccount> profile> settings> Developer settings> Tokens (classic)> Generate Token>Complete repo details> Generate Token
30 days available 
 
 
 
 
 
Create a repository (private or public)
 
 
  • A branch is a snapshot of your repository to which you can make changes.

  • In the child branch, you can build, make edits, test the changes, and then merge them with the main branch.

  • To ensure that changes are made by one member, do not impede or affect the workflow of other members, multiple branches can be created and merged with the main branch.

  • A pull request is a way to notify other team members of the changes and edits made to the main branch.

  •  
     
     
     
     
     
     
     
     
     
     
     
     
     
    Git commands
     
     
     
    gti push -u origin
     
     
     
    Practice
    • create a new local repository using git init
    • create and add a file to the repo using git add
    • commit changes using git commit
    • create a branch using git branch
    • switch to a branch using git checkout
    • check the status of files changed using git status
    • review recent commits using git log
    • revert changes using git revert
    • get a list of branches and active branch using git branch
    • merge changes in your active branch into another branch using git merge 
     
     
     
     
     
     
     
     
    Clonning and Forking
     
     
     
     
     
     
     
     
    Clonning vs Forking
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Repo administration
     
     
    • Multiple roles are involved in managing a project: Developer, Integrator, and Repository Administrator.

      • A Developer working in a group project uses commands like git clone, git pull, git fetch, git push, and git request-pull in addition to the ones needed by a standalone developer.

      • An Integrator in a group project reviews and integrates changes made by others. Integrators use commands like git pull, git revert, and git push in addition to the ones needed by participants.

      • Repository Administrators structure how the repository is organized and how users interact with the repository. They also configure the servers needed for accessing the web services and documentation, define email and index settings, and manage the look and feel of the application.

    • The following table shows various Git commands:

    git init

    git checkout

    git revert

    git format-patch

    git fetch upstream

    git status

    git merge

    git config --global user.email

    git request-pull

    git merge upstream/main

    git add .

    git clone

    git config --global user.name

    git send-email

    git pull upstream

    git commit 

    git pull

    git remote -v

    git am

    git web

    git log

    git push

    git remote rename

    git daemon

    git instaweb

    git reset

    git --version

    git remote add origin

    git remote -v

    git-pull downstream

    git branch

    git diff

    git remote

    git remote add upstream

    git-rerere

     
     
     
     
     
     
     
     
     
     
     
    PRACTICE
     
    cd repo_directory
    git clone <repo_url>


    #made changes

    git add <files>
    git commit -m <message>

    git push

    git fetch
    git pull #(git fetch + git merge)




    # //////////////////////////////////////////////// #

    mkdir myrepo
    cd myrepo

    git config --



    # ///////////////////////////////////////////////// #

    cd /home/project

    mkdir myrepo
    cd myrepo

    git config --global init.defaultBranch main

    git init

    ls -la .git

    touch newfile
    git add newfile

    #to be abailable to commit tell who your are
    git config --global user.email "you@email.com"
    git config --global user.name "your_user_name_here"

    git commit -m "added newfile or commit messageg"

    git branch sub_main_feature_branch

    git branch

    git checkout sub_main_feature_branch

    git checkout -b sub_main_feature_branch



    echo '#New text to test process with new file.' >> newfile

    cat new file

    touch readme.md
    git add readme.md

    git status

    git add .

    git status

    git commit -m "added readme.md modified newfile"

    git log


    # rolling back last commit
    git revert HEAD --no-edit


    # mergin changes
    touch goodfile
    git add goodfile
    git commit -m "added goodfile"
    git log

    git checkout main

    git merge sub_main_feature_branch
    git log

    # delect the merged sub_main_feature_branch
    git branch -d sub_main_feature_branch


     
     
     
    Term Definition
    Branch A separate line of development that allows to work on features or fixes independently.
    Clone A local copy of the remote Git repository on the computer.
    Commit A snapshot of the project's current state at a specific point in time, along with a description of the changes made.
    Continuous delivery (CD) The automated movement of software through the software development lifecycle.
    Continuous integration (CI) A software development process in which developers integrate new code into the code base at least once a day.
    Distributed version control system (DVCS) A system that keeps track of changes to code, regardless of where it is stored. Multiple users work on the same codebase or repository, mirroring the codebase on their computers if needed, while the distributed version control software helps manage synchronization amongst the various codebase mirrors.
    Fork A copy of a repository into your GitHub account.
    GitHub A web-hosted service for the Git repository.
    GitHub branches A branch stores all files in GitHub. Branches are used to isolate changes to code. When the changes are complete, they can be merged back into the main branch.
    GitLab A complete DevOps platform delivered as a single application. It provides access to Git repositories, controlled by source code management.
    Git Free and open-source software distributed under the GNU General Public License. It is a distributed version control system that allows users to have a copy of their own project on their computer anywhere in the world.
    Merge A process to combine changes from one branch to another, typically merging a feature branch into the main branch.
    Pull request A process used to request that someone review and approve your changes before they become final.
    Repository A data structure for storing documents, including application source code. It contains the project folders that are set up for version control.
    SSH Protocol A method for secure remote login from one computer to another.
    Version control A system that allows you to keep track of changes to your documents. This process allows you to recover older versions of the documents if any mistakes are made.
    Working directory A directory in your file system that contains files and subdirectories on your computer that are associated with a Git repository.
     
     
     
     
    PRACTICE
    •  fork existing repository using the UI
    • clone forked repository in the lab environment
    • create a new branch
    • make changes locally
    • add and commit to local branch
    • push changes to your forked repository
    • create a pull request to the upstream repository
     
     
    #fork repo process

    #Good practices:
        # fork repository
        # clone the forked repository

    export ORIGIN=<your_repository_HTTPS_URL>

    git clone $ORIGIN

    ls -la

    cd repo_dir

    git checkout -b new_branch

    git checkout -b new_branch

    git branch

    # made file changes

    git status

    # to see detailed changes

    git diff ./filechange_name

    #q to go out of git command

    git add .

    git add -A #recursively add all files from the top level git folder.

    git status



    #to be abailable to commit tell who your are
    git config --global user.email "you@email.com"
    git config --global user.name "your_user_name_here"

    git commit -m "Adding new stile"

    git status


    # merge to main
    git brachn

    git checkout main

    git merge new_branch

    git log

    # deleting new_branch and push
    git checkout main

    git branch -d new_branch

    git branch

    git push origin main


    # Pull request





     
     
    #final project

    ORIGIN=https://github.com/<unername>/mcino-Introduction-to-Git-and-GitHub.git

    API_ORIGIN=https://api.github.com/repos/<unername>/mcino-Introduction-to-Git-and-GitHub

    curl -s "$API_ORIGIN" | jq -r '.parent.clone_url'

    curl -s "$API_ORIGIN" | jq '.fork'



    git clone $ORIGIN

    cd mcino-Introduction-to-Git-and-GitHub

    git checkout -b bug-fix-typo
    git branch

    sed -i 's/2022 XYZ, Inc./2023 XYZ, Inc./' README.md

    git status
    git diff ./README.md

    git add README.md
    git status

    git commit -m "Fix footer year typo"
    git push origin bug-fix-typo

    git checkout main
    git merge bug-fix-typo
    git push origin main

    git checkout -b bug-fix-revert
    #explore the commit history, and check the commit id to revert
    git log --oneline
    git revert <commit_id>
    git push origin bug-fix-revert

    git log --oneline


    # check the pull request ID, use the online PR instead of the push request ID
    curl -s https://api.github.com/repos/ibm-developer-skills-network/mcino-Introduction-to-Git-and-GitHub/pulls/<Pull-Request-ID> | jq -r '.head.repo.clone_url'

    curl -s https://api.github.com/repos/ibm-developer-skills-network/mcino-Introduction-to-Git-and-GitHub/pulls/8515 | jq -r '.head.repo.clone_url'
     
     
    Creating new repositorie
     
    # ////////////////////////////////////////////////////////////// #
    # Creating new repositorie

    cd /path/to/your/project

    git init
    git add .
    git commit -m "Initial commit"

    git branch -M main
    git remote add origin https://github.com/<your-username>/my-new-repo.git
    git push -u origin main


    # Verification
    git remote -v
    git status
     
    README guides
     
    Contribution guidelines
     
    Git linux systems

    sudo dnf install git-all

    or, apt on Debian-based distributions (e.g. Ubuntu):

    sudo apt install git-all

    On MacOS you can activate Git by typing:

    git version

     

    On Windows based systems, you can install Git Bash by downloading the Git for Windows installer. Git Bash includes popular Linux Bash shell commands (such as ls, pwd, cat, etc.) as well as Git commands.

    You can also get the GitHub desktop for Windows and MacOS, which provides a UI for GitHub on your desktop.

     

    SSH Key

    An SSH key is an access credential in the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for automated processes.

     

     add the ssh key to Github
     
     
    Use repo SSH url 
     
     
    Git is a command line tool for version control management, open source and designed to track the changes in code in a development project. With GitHub as a web-based hosting service or platform for repositories, allow us to: 
    • Created an open source repository
    • Started and managed branch
    • Changed a file and committed those changes
    • Opened and merged a pull request
    There are specific commands to create, change, combine, synchronize, clone or copy code.

    Commands by steps in a plaint way (just like will appear in project development process):

    • Signup to GitHub (intuitive process)
    • Create a repository (explore the options)
    • Install git (git dowload or from terminal)
      • Get the version or update in terminal:
        • git -v
        • git clone https://github.com/git/git
    • Clone the Repository
    Clone the repository and make changes locally, making sure to include an index.html file which will be the landing page for your website.
      • Copy the URL and execute
        • git clone <url>
      • Open in Desktop
      • or Download
    • Connect
      • VS Code
      • RStudio
    • Make Changes
      • Commit
    Each change and associated commit message (explaining what and why a particular change was made).
        • git commit -m "message"
      • Publica
        • git push
        • If are only changes and no new files try to use
          • git add .
          • git commit -am "message" #commit all the changes
      • Pull
        • git pull
          • Heard of collaboration on GitHub
          • @mention for request feedback
    • Merge Conflicts
    Merge your feature branch into the main branch. It will generate some conflicts, GitHub will alert about this. You can make a commit that resolves or use a comments in the pull request to discuss about this conflicts. Is a recommend practice try to delete the feature branch after merge it, and create a new one for new changes.
      • git log
      • If have a mistake, revert back to a previous version
        • git reset
          • git reset --hard <commit> # revert to the version after that commit
          • git reset --hard origin/master #to the version currently stored online on Github
    • Managed branch
      • git branch # to see in which brach you're working
      • git checkout -b <newBrachName> #create a new brach
      • git checkout <brachName> #switch between branches
      • git merge <otherBrachName> #merge working branch with other

    • Forking - a Github fieature

    Repositories

    A repository, or Git project, encompasses the entire collection of files and folders associated with a project, along with each file's revision history. Some relevant components in GitHub:
    • Files
      • The file history appears as snapshots in time called commits. 
      • The commits can be organized into multiple lines of development called branches.
    • Brach
    • Rules
    • Main (production) - feature 
    • Personal Access Tokens (PAT)
    • Public or Private

    Connect to Development Enviroment or Source Code Editor

    RStudio Integration

    RStudio is a integrated development enviroment for R.
    1. Configure the version control en Global Options de la terminal
      1.    Rutas de Aplicación ejecutable: Git
      2.    New Project - Version Control - Select Git
    1. Create a New Project From Repository
      1. New project
      2. Version control
      3. URL
      4. Create
    2. New Project  - version control - git hub - user required information - project
    3. Fallow the instruction, execute in terminal the git command for the desirable action
      1. Save | Commit | Push
    Additional resource:

    Visual Studio Code Integration

    VS Code is a source-code editor made by Microsoft.

    [ver vscode article]


    Additional Resource:

    Entradas populares

    Lo mas consultado

    Entradas populares