Skip to content

Git QuickSheet

  • Clone a repository
    $ git clone https://github.com/YOUR-USERNAME/my-ocean4dvarnet
    
  • Display informations about the remote connexion of a repository.
    $ git remote -v
    
  • Display local repository state informations
    $ git status
    
  • List existing branches
    git branch -l
    
  • Select a branch
    git switch BRANCH_NAME
    
  • Create a branch
    git branch BRANCH_NAME
    
  • Delete a branch
    git branch -d BRANCH_NAME
    
  • Sync main branch of the local repository with the remote upstream repository
    • Only the index
      git fetch upstream main
      
    • Index and workspace (equiv to git fetch, and git merge)
      git pull upstream main
      
  • Update a branch with the content of the main branch.
    • Solution 1: Re-apply the commit of the main branch to the BRANCH_NAME branch. It rewrite history, create new commits. This is the preferred solution, but the modification of commits ID can be a problem when collaborating on a branch.
      git switch BRANCH_NAME
      git merge main
      
    • Solution 2 : Create a new commit with the result of the merge. It Preserve branch history.
      git switch BRANCH_NAME
      git merge main