Definition

Nowadays Git is a standard option to host your code and share it among collaborators. Seems like the best way to introduce it is to show how to:

  • Fork an existing repository and obtain something useful in your own repo
  • Define the remotes you need to determine from where you want to push repo's updates and where to pull your changes
  • Implement your changes Some atomic enhancement like a typo
  • Accomplish a pull request to the parent repository Get a chance to merge your improvements with the main code

Documentation

The definitive guide how-to do all meta-tasks above are at the official Git documentation site.

Fixtures

Fork itself

Just by pushing the button on useful project page. It's enough to get its fork in your repo.

Clone the fork

For illustration purposes lets fork the sample project in my own repo and create the local version of it:

cd /usr/local/share/DVCS/
pwd
ls -la
git clone https://github.com/0--key/talk-python-transcripts.git
ls -la
/usr/local/share/DVCS
total 32
drwxrwsrwx 8 root   staff 4096 Jan  4 15:58 .
drwxrwsr-x 9 root   staff 4096 Dec  7 09:50 ..
drwxrwxrwx 9 antony staff 4096 Dec  7 09:57 0--key.github.io
drwxr-sr-x 9 antony staff 4096 Dec  7 09:55 lib
drwxr-sr-x 7 antony staff 4096 Jan  4 16:23 org-pub
drwxr-sr-x 5 antony staff 4096 Jan  4 15:58 talk-python-transcripts
drwxr-sr-x 6 antony staff 4096 Dec 18 16:19 venv2
drwxr-sr-x 5 antony staff 4096 Dec 19 20:54 venv3
fatal: destination path 'talk-python-transcripts' already exists and is not an empty directory.
total 32
drwxrwsrwx 8 root   staff 4096 Jan  4 15:58 .
drwxrwsr-x 9 root   staff 4096 Dec  7 09:50 ..
drwxrwxrwx 9 antony staff 4096 Dec  7 09:57 0--key.github.io
drwxr-sr-x 9 antony staff 4096 Dec  7 09:55 lib
drwxr-sr-x 7 antony staff 4096 Jan  4 16:23 org-pub
drwxr-sr-x 5 antony staff 4096 Jan  4 15:58 talk-python-transcripts
drwxr-sr-x 6 antony staff 4096 Dec 18 16:19 venv2
drwxr-sr-x 5 antony staff 4096 Dec 19 20:54 venv3

Check the remotes

cd /usr/local/share/DVCS/talk-python-transcripts
git remote -v
origin  https://github.com/0--key/talk-python-transcripts.git (fetch)
origin  https://github.com/0--key/talk-python-transcripts.git (push)
upstream        https://github.com/mikeckennedy/talk-python-transcripts.git (fetch)
upstream        https://github.com/mikeckennedy/talk-python-transcripts.git (push)

Add upstream

cd /usr/local/share/DVCS/talk-python-transcripts
git remote add upstream https://github.com/mikeckennedy/talk-python-transcripts.git
git remote -v
fatal: remote upstream already exists.
origin  https://github.com/0--key/talk-python-transcripts.git (fetch)
origin  https://github.com/0--key/talk-python-transcripts.git (push)
upstream        https://github.com/mikeckennedy/talk-python-transcripts.git (fetch)
upstream        https://github.com/mikeckennedy/talk-python-transcripts.git (push)

Up-to-date local version

cd /usr/local/share/DVCS/talk-python-transcripts
git fetch upstream

Merge the local branches

cd /usr/local/share/DVCS/talk-python-transcripts
git merge upstream/master
Already up-to-date.

Results

Now we have a local version of our forked repository. It is up-to-dated with upstream repository but not synced yet with the origin.

cd /usr/local/share/DVCS/talk-python-transcripts
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

Conclusion



blog comments powered by Disqus

Published

06 September 2016

Categories

git literate programming

Tags