Git Product home page Git Product logo

github_commands's Introduction

Useful GitHub commands

Install Git

sudo apt-get install git

Add existing project to Github

  1. Create repository on GitHub without initializing with README file.

  2. navigate to the directory and initialize: git init

  3. Add the files in local repository and stages them for commit: git add .

  4. commit the files: git commit -m "First commit"

  5. add the URL: git remote add origin https://github.com/username/myproject.git

  6. verify the new URL: git remote -v

  7. push changes: git push origin master

Push to repositoray after making changes

  1. Add the files in local repository and stages them for commit: git add .

  2. commit the files: git commit -m "current commit"

  3. push changes: git push origin master

Pull new changes from remote

  1. git pull is a convenient shortcut for completing both git fetch and git merge in the same command

    If you run into a merge conflict you cannot resolve, or if you decide to quit the merge, you can use git merge --abort to take the branch back to where it was in before you pulled.

  2. Force to overwrite local files:

    git fetch --all

    git reset --hard origin/master

    git pull origin master

Set Username

  1. set Git username for every repository on your computer:

    git config --global user.name "YourUserName"

    Setting your Git username for a single repository:

    git config user.name "YourUserName"

    check username:

    git config user.name

  2. set your email address for every repository on your computer

    git config --global user.email "[email protected]"

    Setting your email address for a single repository:

    git config user.email "[email protected]"

    check email address:

    git config user.email

Set Password

Turn on the credential helper so that Git will save your password in memory for some time. By default, Git will cache your password for 15 minutes.

  1. Set git to use the credential memory cache:

    git config --global credential.helper cache

  2. Set the cache to timeout after 1 hour (setting is in seconds):

    git config --global credential.helper 'cache --timeout=3600'

Delete Commits

Reset the head to the number of commits back by 2 for example:

git reset --hard HEAD~2

and force pushed using:

git push -f origin master

Other commands

  1. Delete file or folder:

    git rm -r file-name.txt or folder then git commit -m "Remove file or folder"

  2. Check status:

    git status

  3. Update combo:

    git add * && git commit -m "something" && git push origin master

  4. Many other commands

github_commands's People

Contributors

tixiaoshan 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.