Git Note

Over the past 2 years, I basically had no idea about how to use git in real development since I only know a few commands such as git add, git commit and git push. Until I became a software developer, I realized the importance of git and agile development. That is why I want to make a blog post about it. In this blog, I summarized the workflow of using git and put some other knowledge like branching and resolving conflicts.


Local Git Workflow

  • Write code
  • Stage changes (git add)
  • Save / Commit changes (git commit)
  • Push changes (git push)
  • Make a pull request

Push local files to a new remote repository

  •   git init
      git remote add origin https://github.com/jiajun2001/demo2.git
      git remote -v
    
      git add .
      git commit -m "add ..."
      git push -u origin master
    

Git Branching

  • We can create a feature branch and work there as a sandbox area
  • Once we write all the code we need and get them all correct, we can merge the feature branch to the master branch
  • We can also create a hot fix branch to fix a quick bug
  •   git branch
      git checkout -b feature // create a new branch
    
      git add .
      git commit -m "add ..."
      git push -u origin feature
    
      git branch -d feature
    

Git Pull Request

  • A request to have your code pulled into another branch

Git Merge Conflict

  • Commit changes or using git stash
  • git pull origin main
  • Resolve the conflicts
  • Commit code
  • git stash apply
  • Resolve the conflicts
  • Commit code

Undoing staging and commit in Git

  • git reset

Go back to a certain point

  •   git log
      git reset --hard f2fb957173f9b9e95a9e595ba1751288377a5c53