Working with Git

Git is a free and open source distributed version control system with branching staging, areas and data assurance.

Cloning

Cloning is how you get a copy of a codebase to your local PC.

$ git clone <<git-url>> [local-repo-name]

Branching

Branching allows you to work on an isolated copy of the code.

$ git checkout <<-b>> <<branch-name>>

-b for creating a new branch.
Without -b will switch the current branch to branch-name.

Committing

Committing adds changes to the repository’s history.

$ git add <<file/path/to/add>>
$ git commit -m "Commit Message Explaining What Changed"

Before committing, you should add the changed files or path you want to commit.

Pulling

Pulling allows you to bring in code changes from a branch on a remote.

$ git pull <<remote-name>> <<brach-name>>

git-pull will fetch and integrate with another repository or a local branch.

Pushing

Pushing allows you to put committed code changes on to a branch on a remote.

$ git push <<-u>> <<remote-name>> <<branch-name>>

-u to set the upstream tracking branch.

Remotes

Remotes are other repositories (usually other copies of the one being worked on, or forks).

$ git remote add <<remote-name>> <<git-url>>

Workflow

  1. Get a github account. Github, or your enterprise site.
  2. At your local PC, generate a SSH key:
$ ssh-keygen [key-name/default rsa]

After running ssh-keygen command, you’ll get two files, one is private key and the other is the publick key. You need to copy the .pub file content (public key) to your github repository in your profile -> settings -> SSH and GPG Keys page, create a new SSH key and paste your public key here.

After above steps, you can work with your github repository with git command line.

  1. Create a repository.

  2. Copy the repository to local PC.

Clone a repository through Clone with SSH,

$ git clone <<git@github.com:account-name/repo-name.git>>
  1. Create or Modify files at your local repo.
  2. Add changes files.
$ git add <<file/path>>
  1. Commit added files.
$ git commit -m "Comments to the changes files"
  1. Push to origin master.
$ git push origin <<master/branch-name>>
  1. If your repository is forked from another repository, after above steps, you need to create a new Pull Request from your forked repository to the remote master.

After this, the remote master will recieve a merge request from you, the owner will take actions to your request after reviewing.

References

Git Branching Remote Branches
Working with Git
git - 简明指南

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值