Git and GitHub
Git and GitHub are not the same thing. Git is an open-source, version control tool created in 2005 by developers working on the Linux operating system; GitHub is a company founded in 2008 that makes tools which integrate with git. You do not need GitHub to use git, but you cannot use GitHub without using git. There are many other alternatives to GitHub, such as GitLab, BitBucket, and host-your-own solutions such as gogs and gittea. All of these are referred to in git-speak as remotes, and all are completely optional. You do not need to use a remote to use git, but it will make sharing your code with others easier.
Configure tooling
Configure user information for all local repositories
1 |
$ git config --global user.name "[name]" |
1 |
$ git config --global user.email "[email address]" |
1 |
$ git config --global color.ui auto |
Branches
Branches are an important part of working with Git. Any commits you make will be made on the branch youre currently checked out to. Use git status to see which branch that is.
1 |
$ git branch [branch-name] |
1 |
$ git checkout [branch-name] |
1 |
$ git merge [branch] |
1 |
$ git branch -d [branch-name] |
Make changes
Browse and inspect the evolution of project files
1 |
$ git log |
1 |
$ git log --follow [ file ] |
1 |
$ git diff [first-branch]...[second-branch] |
1 |
$ git show [commit] |
1 |
$ git add [ file ] |
1 |
$ git commit -m "[descriptive message]" |
Redo commits
Erase mistakes and craft replacement history
1 |
$ git reset [commit] |
1 |
$ git reset --hard [commit] |
Create repositories
A new repository can either be created locally, or an existing repository can be cloned. When a repository was initialized locally, you have to push it to GitHub afterwards.
1 |
$ git init |
1 |
$ git remote add origin [url] |
1 |
$ git clone [url] |
Synchronize changes
Synchronize your local repository with the remote repository on GitHub.com
1 |
$ git fetch |
1 |
$ git merge |
1 |
$ git push |
1 |
$ git pull |