Git Learning

Git Learning

Learning from Codecadamy: https://www.codecademy.com/learn/learn-git

Use Git commands to help keep track of changes made to a project:

  • git init creates a new Git repository
  • git status inspects the contents of the working directory and staging area
  • git add adds files from the working directory to the staging area
  • git diff shows the difference between the working directory and the staging area
  • git commit permanently stores file changes from the staging area in the repository
  • git log shows a list of all previous commits

  • git checkout HEAD filename: Discards changes in the working directory.

  • git reset HEAD filename: Unstages file changes in the staging area.
  • git reset SHA: Can be used to reset to a previous commit in your commit history.

  • git branch: Lists all a Git project’s branches.

  • git branch branch_name: Creates a new branch.
  • git checkout branch_name: Used to switch from one branch to another.
  • git merge branch_name: Used to join file changes from one branch to another.
  • git branch -d branch_name: Deletes the branch specified.

  • git clone: Creates a local copy of a remote.

  • git remote -v: Lists a Git project’s remotes.
  • git fetch: Fetches work from the remote into the local copy.
  • git merge origin/master: Merges origin/master into your local branch.
  • git push origin <branch_name>: Pushes a local branch to the origin remote.

The workflow for Git collaborations typically follows this order:

  1. Fetch and merge changes from the remote
  2. Create a branch to work on a new project feature
  3. Develop the feature on your branch and commit your work
  4. Fetch and merge from the remote again (in case new commits were made while you were working)
  5. Push your branch up to the remote for review

To deploy a website:

//initialize a Git repository 
git init

//In the example above, https://github.com/your-user-name/your-user-name.github.io.git is the remote URL that refers to the repository you created on GitHub earlier. 
git remote add origin https://github.com/your-user-name/your-user-name.github.io.git

//Confirm that the remote was succesfully added
git remote -v

//Add all of your site's content to the Git staging area
git add .

//Save your changes using Git's commit command and the following commit message:
git commit -m "Save my work"

//push the contents of your site up to your repo 
git push -u origin master
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值