Skip to content

Instantly share code, notes, and snippets.

@Ifejeremiah
Last active April 13, 2023 12:29
Show Gist options
  • Save Ifejeremiah/f042a9c4c451d8cc9ab447d751d612d1 to your computer and use it in GitHub Desktop.
Save Ifejeremiah/f042a9c4c451d8cc9ab447d751d612d1 to your computer and use it in GitHub Desktop.

Git Commands

Order of Contents:

  • Get all git branches with remote branches

  • Add remote branch

  • Delete remote branch on local

  • Delete remote branch

  • Create local branch from remote branch

  • Commit to remote project (Open Source)

  • Commit to a remote project (PR In a Team)

  • Get all git branches with remote branches:

    $ git branch -a
    
  • Add remote branch:

    $ git remote add [REMOTE BRANCH VARIABLE] [REMOTE BRANCH URL]
    
    $ git remote add origin [URL]
    

    P.S. REMOTE BRANCH VARIABLE is the remote branch variable you give like, origin

  • Delete remote branch on local:

    $ git remote remove [REMOTE BRANCH NAME]
    
    $ git remote remove origin
    
  • Delete remote branch:

    $ git push [REMOTE BRANCH VARIABLE] -d [REMOTE BRANCH NAME]
    
    $ git push origin -d fix-bugs  
    

    P.S. -d flag means delete | fix-bugs branch would be deleted.

  • Create local branch from remote branch:

    $ git checkout --track origin/<REMOTE_BRANCH_NAME>
    
  • Commit to remote project (Open Source):

    • Clone the master branch:

      $ git clone [URL]
      
    • Inspect the contributors to the repo:

      $ git log
      
    • Create a new git branch for your developments

      $ git switch -c [YOUR BRANCH NAME]
      
      $ git switch -c my-branch
      
    • Stage your changes

      $ git add . 
      
    • Commit changes

      $ git commit -m "[COMMIT MESSAGE]"
      
      $ git commit -m "fixed bug in pipeline"
      

      P.S. give meaningful messages to commits

    • Push your branch to remote repo

      $ git push [REMOTE BRANCH VARIABLE] [YOUR BRANCH NAME]
      
      $ git push origin my-branch
      

      P.S. REMOTE BRANCH VARIABLE is the remote branch variable you give like, origin

  • Commit to a remote project (PR In a Team):

    • Commit changes

      $ git commit -m "[COMMIT MESSAGE]"
      
    • Pull and rebase changes from main

      git pull origin main --rebase
      
    • Push

      git push origin [BRANCH NAME]
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment