Tag Archives: GitHub

How to Use Git

Motivation:

You want to use Git to version your files or share your files with other people.

Solution:
  • Register a GitHub or a GitLab account.
  • Create a GitHub repository or a GitLab project.
  • Download and install a Git client.
  • Generate a personal access token.
  • Pull (checkout) a remote repository (e.g. https://github.com/huybien/asp.net-core.git) to an empty local folder (e.g. C:\Users\admin\Downloads\code).
    git init
    git config user.email "[email protected]"
    git config user.email
    git config user.name "Huy Bien"
    git config user.name
    git config credential.helper ""
    cd C:\Users\admin\Downloads\code
    git remote add origin -f https://github.com/huybien/asp.net-core.git
    git pull origin main
    / * or * /
    git pull origin master
  • Pull (checkout) a remote repository (e.g. https://github.com/huybien/asp.net-core.git) to a local folder that contains existing code (e.g. C:\Users\admin\Downloads\code).
    cd  C:\Users\admin\Downloads\code
    git init --initial-branch=main
    git config user.email "[email protected]" git config user.email git config user.name "Huy Bien" git config user.name
    git config credential.helper ""
    git remote add origin https://github.com/huybien/asp.net-core.git
    git fetch --all
    git add *.*
    git commit -m "new files added"
    git push -u origin main
  • Push local files to a remote empty repository.
    git init
    git config user.email "[email protected]"
    git config user.email
    git config user.name "Huy Bien"
    git config user.name
    git config credential.helper ""
    git add *.*
    git commit -m "first commit"
    git branch -M main
    git remote add origin https://github.com/huybien/asp.net-core.git
    git push -u origin main
  • Push changes to a remote repository.
    git config user.email "[email protected]"
    git config user.email
    git add *.*
    git commit -m "CP form"
    git branch -M main
    git push -u origin main
  • Update (fetch and merge) a local repository.
    git pull origin main
    /* or */
    git branch --set-upstream-to=origin/main main
    git pull
  • Force updating (fetch and overwrite) the current repository.
    git fetch --all
    git reset --hard origin/main
    git clean -fd git pull
  • Force updating (fetch and overwrite) a local repository (e.g. C:\Users\admin\Downloads\code).
    git -C C:\Users\admin\Downloads\code fetch --all 
    git -C C:\Users\admin\Downloads\code reset --hard origin/main 
    git -C C:\Users\admin\Downloads\code clean -fd
    git -C C:\Users\admin\Downloads\code pull
  • Reset (Revert) a local repository to a previous version.
    cd C:\Users\admin\Downloads\code
    git log --oneline
    git reset --hard 4355842
    // where 4355842 is a version id.
  • Remove all cached files.
    git rm -r --cached .
  • Display remote URL.
    git config --get remote.origin.url

     

 

 

Topic 11 – Software Construction

Why do I need to learn about software construction?

Knowing how to write code does not mean that you know how to create real-world software.

In real world projects, you will need to know how to manage your code, how to read the existing code, how to write code following standard styles, how to ensure that your code is working, how to automate your the process of building, testing and deploying your code, how to handle errors in your application, how to optimize your code for better speed, how to write secure code, how to avoid code duplication, how to create readable code, how to create code faster.

That’s why you need to learn about software construction.

What can I do after finishing learning software construction?

You will know how to create real world software with a team.

Hmm! Is it really useful?

If you doubt its usefulness then you can delay learning it until you are tasked to create a software system and you complete a half of it and are stuck there because when you add one more feature you will get tons of bugs due to the new code, or when you finish fixing 1 bug, you get 3 other bugs due to the code modification.

An other scenario is when it takes another person 2 weeks to read 1000 lines of the code that you wrote in order to fix a bug or to add a new feature because your code is unstructured.

Another scenario is when you are asked to improve some existing code for better performance or to refactor some code for clarity before adding a new feature but you do not know how to accomplish the task.

Alright! What should I do now?

Software construction requires a lot of reading. In order to get familiar with software construction you will need to read at least below books. Please read this Steve McConnell (2004). Code Complete. Microsoft Press book first.

After that please read this Jon Loeliger and Matthew McCullough (2012). Version Control with Git: Powerful Tools and Techniques for Collaborative Software Development. O’Reilly Media book.

Alternatively, you can read this Ben Collins-Sussman et al. (2011). Version Control with Subversion book.

After that please read this Paul M. Duvall et al. (2007). Continuous Integration Improving Software Quality and Reducing Risk. Addison-Wesley book.

After that please read this Robert C. Martin (2009). Clean Code: A Handbook of Agile Software Craftsmanship. Pearson Education book.

After that please read
– this Andy Hunt, Dave Thomas and Matt Hargett (2007). Pragmatic Unit Testing in C# with NUnit. Pragmatic Bookshelf book, and
– this Kent Beck (2002). Test Driven Development: By Example. Addison Wesley book.

After that please read
– this Martin Fowler et al. (1999). Refactoring Improving The Design Of Existing Code. Addison Wesley book, and
– its newer version Martin Fowler (2019). Refactoring. Improving the Design of Existing Code. 2nd Edition. Addison-Wesley Professional also.

After that please read
– this Elton Stoneman (2020). Learn Docker in a Month of Lunches. Manning Publications book, and
– this Yevgeniy Brikman (2022). Terraform – Up and Running. O’Reilly Media book.

If you have to work with legacy code then please read
– this Michael Feathers (2004). Working Effectively with Legacy Code. Prentice Hall PTR book, and
– this Diomidis Spinellis et al. (2003). Code Reading: The Open Source Perspective. Addison-Wesley Professional book.

After that if you are familiar with .NET then please read
– this Matthew MacDonald and Bill Hamilton (2003). ADO.NET in a Nutshell. O’Reilly Media book to learn how to use a data provider to access data sources, and
– this Brian L. Gorman (2020). Practical Entity Framework. Apress book to learn how to use an ORM to access data sources, and
– this Suhas Chatekar (2015). Learning NHibernate 4. Packt Publishing book to learn how to use an ORM with mapping technique to access data sources, and
– this Brian Larson (2017). Microsoft SQL Server 2016 Reporting Services. McGraw-Hill Education book to learn how to use a reporting system, and
– this Justin Richer and Antonio Sanso (2017). OAuth 2 in Action. Manning Publications book to learn how to use authentication and authorization frameworks and libraries, and
– this Matt Perdeck (2010). ASP.NET Site Performance Secrets. Packt Publishing book to learn how to reduce a web application response time.

Terminology Review:

  • Version Control.
  • Coding Standards.
  • Unit Tests.
  • Continuous Integration.
  • Refactoring.
  • Legacy Code.
  • Code Reading.
  • Containers.
  • Data Providers.
  • Object/Relational Mapping (ORM).
  • Reporting Services.
  • Authentication.
  • Authorization.
  • OAuth 2.
  • Proof Key for Code Exchange (PKCE).
  • JSON Web Token (JWT).
  • OpenID Connect (OIDC).
  • The Backend for Frontend Pattern.
  • Performance.

After finishing learning about software construction please click Topic 12 – Software Testing to continue.