Git Product home page Git Product logo

git-commands's Introduction

Git-Commands

Collection of git commands that you need to use quite often.

Some great links:

Config related commands:

  • View user details:

    git config user.name

    git config user.email

  • View all details:

    git config --list

  • Set details globally:

    git config --global user.name "<user_name>"

    git config --global user.email "<email>"

    Not recommended to use global settings, better use project level settings. Helpful if you have multiple accounts.

  • Set details at project level:

    git config user.name "<user_name>"

    git config user.email "<email>"

    More explanation: http://alvinalexander.com/git/git-show-change-username-email-address

Remote related commands:

  • Get remote repository to local:

    git clone <repository_url>

  • List all existing remotes:

    git remote -v

  • Add remote:

    git remote add <remote_name> <repository_url>

  • Update/Change remote url:

    git remote set-url <existing_remote_name> <new_url>

  • Remove remote:

    git remote remove <remote_name>

    More Explanation: http://help.github.com/articles/changing-a-remote-s-url

Ignore related commads:

Branch related commands:

  • View branches:

    git branch

  • Switch to a branch:

    git checkout <branch_name>

  • Switch to a branch igorning non-commited changes on current branch

    git checkout -f <branch_name>

    More explanation: http://stackoverflow.com/questions/1304626/git-switch-branch-and-ignore-any-changes-without-committing

  • Get a remote branch on local and switch to it:

    git fetch && git checkout <branch_name>

  • Cut a new branch from an existing branch and switch to the newly created branch:

    git checkout -b <new_branch_name> <existing_branch_name>

  • Save changes in the branch (on local):

    git commit for bigger commit messages

    git commit -m "<commit_message>" for smaller commit messages

  • Push changes from local branch to remote branch:

    git push -u <remote_name> <branch_name> if branch is created locally and it doesn't exist at remote yet,

    git push <remote_name> <branch_name> otherwise

  • Rename branch:

    git branch -m <new_name> if on the branch that needs to be renamed:

    git branch -m <old_name> <new_name> if on different branch:

    The above is enough if the branch only exists in your local, but if the branch has been pushed to remote, follow these two additional steps:

    git push origin :<old_name> <new_name> This will delete old_name remote branch and push new_name local branch

    <switch to branch and> git push origin -u <new_name>This will reset the upstream branch for the new-name local branch:

    More explanation: https://multiplestates.wordpress.com/2015/02/05/rename-a-local-and-remote-branch-in-git/

  • Merge a branch with another:

    git checkout <destination_branch>

    git merge <source_branch>

    I typically merge using GUI(IntelliJ for Java Projects)

  • Delete local branch:

    git branch -d <branch_name>

    git branch -D <branch_name> if you have uncommited/unmerged changes:

    More explanation: http://stackoverflow.com/questions/2003505/how-to-delete-a-git-branch-both-locally-and-remotely

Revert related commands:

git-commands's People

Contributors

viiicky avatar

Watchers

James Cloos avatar Swati Singh 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.