git tutorial for Beginner
Basic Workflow
- create
mkdir git_test //then
git init
- base
echo "I am a git repo." > README
//make a README file
git status
//use git status to scan which files aren’t being tracked, have been modified, deleted, etc.
PS D:\silence\Desktop\file\The road of learning\learngit\git_learn> git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
Test
nothing added to commit but untracked files present (use "git add" to track)
git add README or git add .
//Stage” your changes.
git commit -m "it my second commit"
//Commit the changes
PS D:\silence\Desktop\file\The road of learning\learngit\git_learn> git add . PS D:\silence\Desktop\file\The road of learning\learngit\git_learn> git commit -m "it my second commit" [master ad26fe7] it my second commit
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .README.un~
create mode 100644 README~
create mode 100644 Test
//we can use git checkout to reset our file to Previous version
Remote repositories (on github)
//add remote repositories in your git config
git remote add origin https://github.com/Alan-Py/Mygitlearn.git
//push our local respositorize to remote
git push origin master
//pull the remote respositorize and merge to local
git pull origin master
deep dive
Through the above operations, you have a basic understanding of git, then we can have a deeper learn in git. Of course it’s also a basic operation for git
//use branch
git checkout -b develop-feature
//we can del some file in branch master
git checkout master
git add .
git commit -a -m 'third commit'
//to recover master,use merge
git merge develop-feature
we can use ssh to connect to github
//first create your key
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
//then add public key to github
//modify your ssh config file like
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_edgithub
//Test it
ssh -T git@github.com
so ,we can have an initial understanding of git.