Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
  • See more information about a particular remote

    git remote show [remote-name]
    
    git remote show origin
    
  • Create a new branch and switch into it

    git checkout -b feature/new_branch
    
  • Create a new branch and switch into it from a previous commit

    git checkout -b branch_name <commit-hash or HEAD~3>
    
  • Delete a local branch

    git branch -d the_local_branch
    
  • Rename branch

    // Start by switching to the local branch which you want to rename:
    git checkout <old_name>
    // Rename the local branch by typing:
    git branch -m <new_name>
    // Push the <new_name> local branch and reset the upstream branch:
    git push origin -u <new_name>
    // Delete the <old_name> remote branch:
    git push origin --delete <old_name>
    
  • checkout in a new remote branch

    git fetch
    git checkout --track origin/feature/new_branch
    // to fix previous track error
    git branch new_branch -u origin/new_branch
    
  • add remote

    git remote add origin https://<username>@bitbucket.org/<username>/<repo_name>.git
    
  • change remote

    git remote set-url origin https://<username>@bitbucket.org/<username>/<repo_name>.git
    
  • tell Git to convert CRLF to LF on commit

    git config --global core.autocrlf input
    
  • show all files involved in a commit

    git diff-tree --no-commit-id --name-only -r dsjfifjdksjdfjdsk
    
  • add annotated tag

    git tag -a v0.1 -m "demo version"
    git show v0.1
    # show all tags with messages
    git tag -n
    
  • remove annotated tag

    # locally
    git tag --delete tagname
    # remote
    git push --delete origin tagname
    
  • clone a specific tag

    git clone <repo_url> --branch v1.1
    
  • clone in the current folder

    git clone <repo_url> .
    
    • specify an SSH key when cloning a git repository
      GIT_SSH_COMMAND="ssh -i ~/.ssh/<key>" git clone [email protected]
      
  • by default, the git push command does not transfer tags to remote servers

    git push --tags
    git push origin master --tags
    
  • change last commit message

    git commit --amend -m "an updated commit message"
    
  • go back to the previous commit and remove everything after it

    git reset --hard HEAD~1
    
  • go back to a previous commit and remove everything after it

    git reset --hard <commit-hash>
    
  • working with remote

    #show remote
    git remote -v
    git remote remove origin
    
  • change from HTTPS to SSH format

    git remote set-url origin [email protected]:YOUR-USERNAME/YOUR-REPOSITORY.git
    
  • ignore file permission changes (true in prod)

    git config core.fileMode false