A no bullshit guide to getting a project on GitHub.
We need to either create a new repository or clone an existing one.
Create a new directory, add some files and execute:
$ git init
to create a new git repository.
To create a local copy of an existing GitHub repository:
$ git clone [https://github.com/username/project.git]
This will create a working copy of the repository on your machine.
It's now a good idea to see what Git files Git can see:
$ git status
Any 'untracked' files need to be added, we'll do that next.
Your files are currently untracked by Git; we'll make Git take notice of them with:
$ git add <filename>
$ git add .
This will add your proposed changes to the Index.
To actually commit your changes, use:
$ git commit -m "Commit message"
Your files are now committed to the HEAD, but are not in your remote repository yet.
Finally, ypi need to push your changes from the HEAD of your local working copy and send them to your remote repository on GitHub.
If you didn't clone an existing repository earlier you first need to add the remote server you wish to push to before you can push your changes to the server:
$ git remote add origin [https://github.com/username/project.git]
If you did clone an existing remote repository simply execute:
$ git push origin master
Make sure master is whatever branch you want to push your changes to. If you're riding solo on a project this will likely always be master.
Branches are handy for working on a project independently without affecting other developers' shit. You can then merge your changes back to the master branch when you're done.
To create a new branch called "awesome_feature" and swith to it, use:
$ git checkout -b awesome_feature
You can switch back to the master branch with:
$ git checkout master
To delete the "awesome_feature" branch:
$ git branch -d awesome_feature
Your branch is only of use to you unless you push it to your remote repository. Push your "awesome_feature" branch with:
$ git push origin awesome_feature
To update your local repository to the most recent commit you can use:
$ git pull
This will fetch and merge remote changes to your working directory. Handy, huh?
You can also merge your "awesome_feature" branch into your active branch (e.g. master) with:
$ git merge awesome_feature
Sometimes Git isn't able to automatically merge your changes. If this happens you are responsible for merging any conflicts yourself manually by editing the files Git flags up.
After making your changes, you need to mark them as merged with:
$ git add <filename>
If you would like to preview your changes before merging use:
$ git diff <source_branch> <target_branch>
When you rename a repository, all existing information is automatically redirected to the new name (e.g. Issues, Wikis, Stars and Followers).
All web traffic will be redirected and all git clone
, git fetch
, or git push
operations targeting the previous location will continue to funtion.
However, it's recommended to update any existing local clones to point to the new repository URL with:
$ git remote set-url origin <new_url>