Uploaded by Mustafa Magdy

git commands

advertisement
** create empty repository :
git init
---------------------------------
** set your name and email :
git config --global user.name "your name"
git config --global user.email "email@example.com"
---------------------------------------------------
** link your local repo. with github a repository : (only if you have an empty repository on github and you are the first one to add things to it)
---------> git remote add origin https://github.com/.......... (link of your repository on github)
** to create github public key :
-----> ssh-keygen -t rsa -b 4096 -C "engineermostafa10@gmail.com"
-----> cat ~/.ssh/id_rsa.pub ---> then copy returned message --> open SSH keys at setting(github) and paste the copied message and save it
-----> ssh -T git@github.com ---> to test connecting to github
** link your local repo. with github a repository : (by using github public key)
---------> git remote add origin git@github.com:.......... (link of your repository on github)
--------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
** To confirm Changes :
- first adding all files to stagging area -----> git add .
- to remove file from stagging area ----------> git reset head FileName
- then commit with a suitable commit message --> git commit -m "your commit message"
- to view status -----------------------------> git status
- to view commits log (history) ---------------> git log
---------------------------------
** to push your commits to the github repository:
- to view the current branch (main) ----------> git branch
- to view the current remote (origin) --------> git remote -v
- to push your commits ---------------> git push -u RemoteName BranchName
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
** to download the repository to your pc :
-----------> git clone https://github.com/............ (link of the repo.)
** to pull the latest update from github to your computer :
-----------> git pull RemoteName BranchName
--------------------------------------------------------------------------------------
** لو انت كتبت حاجات بالغلط وحبيت تلغيها كلها وترجع لآخر حاجة بعد آخر كومميت
git reset --hard
---------------------------------------------------------------------------------
** Branches **
--- to view the current branch ---> git branch
--- to create a new branch ---> git branch BranchName
--- to convert to anther branch ---> git checkout BranchName
--- to remove branch ---> git branch -d BranchName
--- to create a new branch and convert to him ---> git checkout -b BranchName
--- to rename branch ---> git branch -m BranchName
////////////////////////////////
git checkout master git branch main master -f git checkout main git push origin main -f 
Download