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 <<[email protected]: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 - 簡明指南

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章