Git 初学

# Navigate to your folder cd /path/to/your/folder # Initialize the Git repository git init # Configure user identity git config user.name "AkiaHaha" git config user.email "daniel666cqu@163.com" # Create a README file (optional) echo "# My Project" > README.md

clone your github repository to a new pc

#Set up the SSH key ##Generate an SSH Key ssh-keygen -t rsa -b 4096 -C "daniel666cqu@163.com" ## start the SSH agent: eval "$(ssh-agent -s)" ## Add Your SSH Key to the Agent ssh-add ~/.ssh/id_rsa ##display and copy your key cat ~/.ssh/id_ras.pub ## test the SSH conction ssh -T git@github.com ### And then you will see a message like this: ### Hi YourUsername! You've successfully authenticated, but GitHub does not provide shell access.

add modification and push to your github storage

# Stage all files git add . # Commit the changes git commit -m "Initial commit" # Link to the remote repository (optional) git remote add origin https://github.com/YourUsername/YourRepoName.git # Push the changes to GitHub (if linked) git push -u origin main

switch between branches and commit editions

## Branches # List all branches git branch -a # switch to a existed branch git check <your_branch_name> # creat and switch to a new branch git checkout -b <new_branch_name>

## Commitment #1. view the commit history git log # it will feedback messages like =>>>>>>>>>>>>>>> # commit befd480326ddbdc55d729b38303e9b056502a0fa # this is the commit hash # Author: AkiaHaha <daniel666cqu@163.com> # Date: Wed Aug 14 20:07:31 2024 +0800 # the stable version that could quat at 0.25m #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #2. switch to a specified commit edition git checkout <commit_hash> #3. create a new branch at current commit git checkout -c <new_branch_name>

Delete branch

  1. check to a different branch, forbid to delete the branch currently on

    git checkout <another_branch_name>

  2. delete the branch you don't need

    git branch -d <branch-name>

  3. force the deletion

    git branch -D <branch-name>

  • Git

    Git 是 Linux Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。

    211 引用 • 358 回帖

相关帖子

回帖

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...