2. Git

2.1. Commands

Code Meaning
$ git clone https://user@bitbucket.org/username/file.git
Clone the repository to the required directory. This will create a directory called “file” with the repository inside it
$ git fetch origin
Fetch any changes from origin
$ git merge origin/master
Merge the origin with the master branch
$ git pull origin master
Fetch any changed from origin AND merge the origin with the master branch
$ git pull
Fetch any changed from origin AND merge the origin with the master branch (origin and master are defaults)

2.2. How to configure git for a machine?

  • This is done once per machine
Code Meaning
$ git config --global user.name "Andrew Roberts"
$ git config --global user.email en9apr@hotmail.co.uk
This identifies the user of git

2.3. How to download a repository?

  • cd into the directory you want the repository downloaded to
  • It will create a subfolder with the same name as the repository on github
Code Meaning
$ git clone https://github.com/en9apr/sphinx.git
This will clone the .git repository and create a new subdirectory called sphinx

2.4. How to put a directory under version control?

  • Firstly create a repository in GitHub (it must be public - unless you want to pay)
  • Alternatively GitLab can be private and you don’t have to pay https://gitlab.com
  • cd into the directory you want under version control
Code Meaning
$ cd existing_folder
Change to existing folder
$ gedit README.md
Create a readme file (add some text to this)
$ git init
Initilises git
$ git remote add origin https://gitlab.com/apr207/twoPhaseEulerSrivastava.git
Adds the origin to a github respository
$ git add .
Create a dummy file. Add all changes
$ git commit -m "Solver before any changes are made"
Commit the changes
$ git push -u origin master
Pushes the changes from the master to the origin

You can now add new files and repeat the add, commit and push stages.

2.5. How to change the origin?

Code Meaning
$ git remote rm origin
Removes the current origin
$ git remote set-url origin https://gitlab.com/apr207/twoPhaseEulerSrivastava.git
Changes the origin to github respository
$ git add -A
Add all changes
$ git push -u origin master
Pushes the changes to the origin (username and password required)

2.6. How to commit changes to git and push to respository?

Code Meaning
$ git add .
Add all changes
$ git commit -m "The new changes are identified by this sentence"
Commit the changes
$ git push
Push the changes to the origin (will have to enter username and password for the origin)

2.7. How to commit three folders to git and push to respository?

Code Meaning
$ git add 0 constant system
Add all changes
$ git commit -m "The new changes are identified by this sentence"
Commit the changes
$ git push -u origin master
Push the changes to the origin (will have to enter username and password for the origin)