Skip to content

roymj88/git-commands-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 

Repository files navigation

git-commands-helper : Basic git commands

Here is a list of some basic Git commands that will help you get started with git.

  1. Checkout a new branch

    git clone git-repo-url
    eg:-   
    git clone https://github.com/roymj88/git-helper.git
       
    
  2. Create a new local repository

    git init
    
  3. Create a new branch from current working branch and switch to it

    git checkout -b <new-branch-name>
    
  4. Switch to a new branch

    git branch <branch-name>
    
  5. List all available branches

    git branch
    
  6. Check status of files

    git status
    
  7. Add files for commit

    git add <file-name>
    OR
    git add <file-name-1> <file-name-2> <file-name3>
    OR
    git add *
    
    
  8. Remove files for commit

    git rm <file-name>
    
  9. Commit

    git commit -m "Message for commit"
    
  10. Pull - Update local repo with latest update from server

    git pull 
    
  11. Push - Update changes to repository

git push origin master 
#Updates 'master' branch

git push origin <branch-name> 
#Updates corresponding branch
  1. Stash - Save changes made in the current index and working directory for later
git stash
  1. Stash Apply - Apply stashed changes
git stash apply
  1. Merge
git merge <branch-name>
#Merges a different branch into your active branch
  1. Setting username in Git
git config --global user.name "user name"
#Set a new user name

git config --global user.name
#Displays the user name
  1. Setting email in Git
git config --global user.email "[email protected]"
  1. Modify the Previous Commit's Message
git commit --amend -m "New commit message"
  1. View commits of a certain author

    git log --author=user.name
    
  2. View all commits

    git log
    
  3. List of tags

git tag
  1. Config value for color
#Edit Color scheme

color.status=auto
color.interactive=auto
color.diff=auto
  1. Export Git Repo
git archive --format=zip -9 HEAD -o <file-name>
  1. Search
#Search the working directory for foo()
git grep "foo()"
  1. Get Stash List
#view stashes currently on the stack
git stash list
  1. Revert to previous version of a particular file
#Get the commit history of the file
git log path/to/file

#Checkout to particular version using the commit hash obtained
git checkout <hash> path/to/file

  1. Create new branch from an existing branch
#Creates new_branch branch off existing_branch
git checkout -b new_branch existing_branch
  1. See what's in the most recent stash without applying stash
git stash show -p
  1. View the content of an arbitrary stash
git stash show -p stash@{1}

About

Basic git commands

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published