Skip to content

Latest commit

 

History

History
123 lines (95 loc) · 3.14 KB

README.md

File metadata and controls

123 lines (95 loc) · 3.14 KB

Git: useful command line instructions

Git global user setup

git config --global user.name "Dmytro Zarezenko"
git config --global user.email "[email protected]"

Create a new repository

git clone https://github.com/dzarezenko/devTips.git
cd devTips
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Init repository in existing folder

cd existing_folder
git init
git remote add origin https://github.com/dzarezenko/devTips.git
git add .
git commit -m "Initial commit"
git push -u origin master

Bind remote repository with local one

git add .
git commit -m "Initial commit"
git remote add origin https://github.com/dzarezenko/devTips.git
git pull origin master --allow-unrelated-histories
git push -u origin master

Switch existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin https://github.com/dzarezenko/devTips.git
git push -u origin --all
git push -u origin --tags

Store credentials

For temporary store credentials in memory use:

git config --global credential.helper cache

For permanent store use:

git config --global credential.helper store

After that use:

git config --global credential.https://github.com.username github

or

git config --global credential.https://[email protected] bitbucket

Then clone repository and type password when it will ask you.

More details:

  1. gitcredentials - providing usernames and passwords to Git
  2. How to provide username and password when run git clone [email protected]?

Revert commit

Revert last commit locally:

git reset --soft HEAD~1

Apply revert on the remote repository:

git push -f origin local_branch_name:remote_branch_name

More information:

  1. What is difference between git reset --hard HEAD~1 and git reset --soft HEAD~1?
  2. git-reset - Reset current HEAD to the specified state

Case sensitive file names

To tell Git to be case-senstive, simply set this setting to false...

git config core.ignorecase false

Remove a file from a Git repository without deleting it from the local filesystem.

git rm --cached filename.ext

Transfer a gist to a GitHub repository

https://gist.github.com/ishu3101/830b556b487de5d69690