Skip to content
Vital-jan edited this page May 4, 2021 · 6 revisions

different git accounts for ssh:

git config --local --get user.name (git -config -global)
git config --local --get user.email
git config --local user.email "user_email"
git config --local user.name "user_name"
ssh-add -D // delete all cached keys before
ssh-add ~/.ssh/{key1_filename} // without .pub
ssh-add ~/.ssh/{key2_filename} // without .pub

configure ~/.ssh/config file:

#user1 account
Host user1.github.com
HostName github.com
User git
IdentityFile ~/.ssh/{key1}
#user2 account
Host user2.github.com
HostName github.com
User git
IdentityFile ~/.ssh/{key2}
#activehacker account
Host github.com-activehacker
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_activehacker
#jexchan account
Host github.com-jexchan
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_jexchan

new git project:

git init

add to .gitignore file all files & folder not for share

git add * (git add <file | folder>)

git commit -m <commit_message>

git remote add <origin> <url>

git push origin master


clone existing repository:

git clone <url>

refresh existing project:

git remote add <upstream> <url>

git remote remove <name>

git remote -v : list remote urls

git pull upstream master

git push <origin> <branch>


git branch - show all branches and current branch

git checkout <branch> - select branch

git checkout -b <branch> - create new branch & switch to it

git commit -m <commit_message> - create a new local commit on current branch

git log - commits history list

git log --name-status - filenames in commit

git reset --soft HEAD~1 - back to 1 commit

git reset --soft <commit_name> - ??

git reset --hard <commit_number>

git rm <filename> - delete file from commit

git stash

git revert <commit1> <commit2> <commit…​> ???

git merge ???

git remote add <origin> https://github.com/…​ - new connect to remote repository

<origin> - fork

<upstream> - primary repository

git remote remove <origin> - delete remote

git remote - remotes list

git push <origin> <branch>

<origin> - url path to fork

How to work on a task:

create a new branch

>git checkout -b branch_name

or switch to existing branch

>git checkout branch_name

make your changes…​..

add your changes to local repo

>git add path_to_file_or_folder (. for current)

commit your changes to local repo, message is required

>git commit -m "commit message"

push your changes to remote repo

>git push origin branch_name

go to github to your branch and open PR (pull request)

after at least one +1 you can merge your PR to upstream

How to update master:

>git checkout master

>git pull upstream master

>git push origin master

>git checkout branch_name

>git rebase master

Clone this wiki locally