Giter VIP home page Giter VIP logo

git's Introduction

Git

A reference for useful git commands with explanation of its usage.

Begin

  1. To creates a folder
    mkdir <DIR NAME>
    
  2. To open the folder in vs code.
    code .
    
  3. To initialize an empty git repository.
    git init
    

    Note:

    1. Creates .git file which implies this is a repository.
    2. Deleting .git removes the repository status of the folder.
  4. To check for tracked and untracked files.
    git status
    
  5. To create the .gitignore file,
    touch .gitignore
    

    Then open the .gitignore file and add paths of files and folders that needs to be neglected when syncing to remote repository(for instance the node modules directory).

    Note: Before adding files to track using the following commnad. Add path of file or folder that need not be tracked to .gitignore file.

  6. To track all files.( i.e, add these files to tracked label so that it can be commited later)
    git add .
    
  7. To commit changes locally.
    git commit -m "<COMMIT MESSAGE>"
    
  8. At times with latest git the branch might be master you can change it to main using,
    git branch -M main
    

Sync Changes

Assuming you have now created some files in your directory and you want to save them in your GitHub.

  1. To set up remote where the changes need to be saved or synced later

    git remote add origin <REMOTE GITHUB REPO URL>
    
  2. To check if remote origin is configured,

    git remote -v
    
  3. To push changes,

    git push origin <BRANCH NAME>
    

    The following might even come handy for setting the upstream branch

    git push -u origin <BRANCH NAME>
    

    or

    git push --set-upstream origin <branch name>
    

    Note: Once upstream is set next time onwards you can push just using git push.

  4. To pull changes, (it does fetch + merge)

    git pull origin <BRANCH NAME>
    

    Note: if git pull gets aborted due to files in the local might be lost during merge and if you want to override and still merge.

    git fetch <URL> <branchname>
    
    git reset --hard fetch_head
    

Working with feature branches:

  1. To make a copy locally of some repository and then work
    git clone <REMOTE REPO URL>
    
  2. To work on a feature without disturbin the main or base branch use the following command to copy and create a new branch
    git checkout -b <FEATURE BRANCH NAME>
    
  3. To check which branch we are locally working on,
    git branch
    

Reference:

Ref: https://www.nobledesktop.com/learn/git/stage-commit-files
Remove Sensistive Data: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository

git's People

Contributors

fuzail22 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.