Skip to content

Instantly share code, notes, and snippets.

@moradi-morteza
Last active March 19, 2021 06:54
Show Gist options
  • Save moradi-morteza/36ab5b29d97c1abbe5d6e76eee94d2d4 to your computer and use it in GitHub Desktop.
Save moradi-morteza/36ab5b29d97c1abbe5d6e76eee94d2d4 to your computer and use it in GitHub Desktop.
[git]

sudo apt install git-all sudo apt-get remove git sudo apt-get remove --auto-remove git // with dependencys // If you also want to delete configuration and/or data files of git from Ubuntu Trusty then this will work: sudo apt-get purge git sudo apt-get purge --auto-remove git // with dependencys

git config --global user.name YOUR_USRE_NAME // set username git config --global user.email YOUR_EMAIL // set email git config --global user.name // show username git config --global user.email // show email git config --global --list // check all info // config file is in : nano ~/.gitconfig

git init git add . git commit -m "messate" git push origin master //git push

git checkout . // ignore change git fetch origin // see change
git merge origin/master // merge git checkout master // switch to master brach git pull origin master

git clone https://gitlab.com/mabnagroupeaf/note-server.git //clone via https - You can either clone it via HTTPS or SSH. git clone git@gitlab.com:mabnagroupeaf/note-server //clone via ssh

git clone https://USER_NAME:PASSWORD@gitlab.com/mabnagroupeaf/shop-project // clone via https - with username and password from private project in another accout

/* If you chose to clone it via HTTPS, you’ll have to enter your credentials every time you pull and push. With SSH, you enter your credentials only once. */

$ git config credential.helper cache $ git push http://example.com/repo.git Username: Password:

[work for 5 more minutes] $ git push http://example.com/repo.git [your credentials are used automatically]

// FOR GITLAB //Create a new repository // NOT NEED TO CREATE FOLDER***********
git clone https://gitlab.com/mabnagroupeaf/note-server cd test touch README.md git add README.md git commit -m "add README" git push -u origin master

//Push an existing folder cd existing_folder git init git remote add origin https://gitlab.com/moradiemails/test.git git add . git commit -m "Initial commit" git push -u origin master

//Push an existing Git repository cd existing_repo git remote rename origin old-origin git remote add origin https://gitlab.com/moradiemails/test.git git push -u origin --all git push -u origin --tags

// ---------------- Errors error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received. fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed // this error solved by:
It happens more often than not, I am on a slow internet connection and I have to clone a decently-huge git repository. The most common issue is that the connection closes and the whole clone is cancelled.

After a lot of trial and errors and a lot of “remote end hung up unexpectedly” I have a way that works for me. The idea is to do a shallow clone first and then update the repository with its history.

$ git clone http://github.com/large-repository --depth 1 $ cd large-repository $ git fetch --unshallow

// change previous commit first : git add . git commit --amend git push --force // if you do not add file to stage this comman just change message of commit

git rm -r --cached bin/

// create ssh key for git - github ------------------------------------ cd ~/.ssh ssh-keygen -t rsa -b 4096 -C "moradiemails@gmail.com" press enter [default create id_rsa] or enter your own rsa name like github_rsa its important to you use form : /c/Users/Shaparak/.ssh/id_rsa_github_laptop_morteza password password

clip < ~/.ssh/id_rsa_github.pub add containt of rsa.pub to github
// add key to ssh-agent eval $(ssh-agent -s) // check ssh-aget is running ssh-add ~/.ssh/id_rsa_github // add key to ssh-agent enter password

// check connection is done or not ssh -T git@github.com

// add this key to github or gitlab ------------------------------------

// chekc git remote mode : https or ssh git remote -v
// change git remote https to ssh git remote set-url origin git@github.com:USERNAME/REPOSITORY.git // change git remote ssh to https git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment