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
- Get a github account. Github, or your enterprise site.
- 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.
Create a repository.
Copy the repository to local PC.
Clone a repository through Clone with SSH
,
$ git clone <<[email protected]:account-name/repo-name.git>>
- Create or Modify files at your local repo.
- Add changes files.
$ git add <<file/path>>
- Commit added files.
$ git commit -m "Comments to the changes files"
- Push to origin master.
$ git push origin <<master/branch-name>>
- 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.