git config --global <option>
configures git settings. At minimum, you should set:
user.name "Your Cool Name"
user.email [email protected]
core.editor -flag yourfavoriteeidtor
You can check config settings with git config --list
You can also configure locally and system-wide with:
git config --local
git config --system
Two options:
git init
in an existing foldergit clone https://github.com/username/reponame.git
to get an existing repository
The general process to track changes in a repository
- edit your file(s)
git status
to check that the status of the file/repositorygit add <filename>
git commit -m "Short, descriptive message of change"
git status
to check that the working directory is now cleangit log
to see that your commit shows up
git rm <filename>
will remove the file and show the changes in the staging area. This is the same asrm <filname>; git add <filnename>
git mv <file1> <file2>
will rename file1 to file2. This is the same asmv file1 file2; git rm file1; git add file2
git reset HEAD <filename>
will unstage a file that has been staged for commitgit checkout -- <filename>
will bring us back to the version of the file of our last commit. It will permanently remove any changes that haven't been committed.
git branch <branchname>
creates a new branch called branchname off of HEADgit branch <newbranch> <oldbranch>
creates a new branch called newbranch off of oldbranch.git branch -d
will delete a local copy of a branchgit checkout <branchname>
will move HEAD from its current location to the most recent commit of branch branchname.git checkout -b <branchname>
will create a branch branchname off of the current branch, and move HEAD from the current branch to branchname.git checkout <commidID>
will move HEAD from the tip of the current branch to a commit. This will put you in detached HEAD state.git merge <branchname>
will merge branchname into the current working branch
git remote add <remotename> <url>
will add a remote by remotename to your repository and it will be associated with the specified URL.git remote rm <remotename>
will remove a remote called remotenamegit fetch <remote> <branch>
will get a copy of branch from remote.git merge remote/branch
will merge remote/branch into the current working branch.
- A fork is a copy of a repository associated with your user account. You
often will not have push permissions to a project, but you will always have
push permissions to your own fork. You almost always want to set
origin
to track your fork and set the organization's home repo toupstream
or something that will be memorable for you. - A pull request is a request to a project to pull your changes (i.e. fetch+merge) your changes into a particular branch. Pull requests can be located on the same remote (e.g. project/coolfix to project/master) or from a fork (e.g. youruseraccount/coolfix to project/master).
- An issue is a report of unexpected behavior in a project or an error/bug report.
- You can reference issues in pull requests and other issues. See:https://help.github.com/articles/closing-issues-using-keywords/ These references help make repository maintenance easier. If a PR is merged, issues can be automatically closed if proper language is used in the reference.
- All of your repositories should have a license file and a readme. The
license can protect you and your work and ensure you get proper attribution for what you're putting online. The readme can help interested users and individuals to know more about the repository without digging into the code. This is also a good place to link work that you reference in your repository and also direct users how to install or build the work in the repo. github automatically renders README files in each folder.