Git
Git is a Version Control System, or VCS, which allows you to save a snapshot of your coding project at any time you want.
Jargon:
- Repository: A collection of files tracked by Git.
- Commit: The action of storing a new snapshot of the repository's state in the git history. As a noun, it refers to a single point in the Git history.
- Staging: staging a file means that you have marked it for a commit.
To learn commands on the unix/linux command line, read The Linux Command Line for Beginners.
Commands
-
git statusprint what is currently going on with the repository -
git add .adds all (un-staged) files in your repository in the staging area. -
git commit -m "a message to commit with"commits the file.git commit -am <filename(s)> "message": add files and commit changes all in one
-
git logchecks commit history. The numbers after the commit field represent the hash value of the commitgit reflog: print a list of all the different references to commits
-
git checkout specific-commit-idreverts to a previous comit -
git reset --hard <commit>: reset the repository to a given commit. Use it if you want to undo staging of a modified file. -
git clone <url>: take a repository stored on a server (like GitHub) and downloads it -
git clone <url> folder-name: clone to folder-name -
git clone -b <branch> <url>: clone a specific branch -
git push: push any local changes (commits) to a remote server (push only after you staged and committed the changes) -
git fetch: download all of the latest commits from a remote to a local device -
git pull: pull any remote changes from a remote server to a local computer -
git branch: list all the branches currently in a repository -
git branch <name>: create a new branch called name -
git checkout <name>: switch current working branch to name -
git merge <name>: merge branch name into current working branch (normally master) -
git merge origin/master: merge origin/master, which is the remote version of a repository normally downloaded with git fetch, into the local, preexisting master branch -
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git:changing a remote's URL.
See more commands here, or learn more here
.gitignore
A .gitignore file specifies intentionally untracked files that Git should ignore
Generall ignore:
- files that don't belong to the project like
.DS_Store - Files that are generated like those in the build folder
- Libraries
- Credentials and secretes
Use this tool to generate one.
GitHub
GitHub (cloud-based platform that hosts Git repos and facilitates team collab) is not the same as Git (a version control system)
The GitHub Flow entails:
- Communicating in issues
- Creating branches (for adding/updating features)
- Using pull requests to introduce changes
- Merging changes.
You must take intro to github.
Remote repo
git clone <url>: take a repository stored on a server (like GitHub) and downloads itgit push: push any local changes (commits) to a remote serverpushonly after you staged and committed the changes
git fetch: download all of the latest commits from a remote to a local devicegit pull: pull any remote changes from a remote server to a local computer
Merging
A merge conflict is resolved when you remove all lines and code that are not wanted and push the results.
Branching
The ability to move in multiple directories simultaneously.
HEAD refers to the current branch being worked on. When a different branch is "checked out", the HEAD changes to indicate the new working branch.
-
git branch: list all the branches currently in a repository -
git branch <name>: create a new branch calledname -
git checkout <name>: switch current working branch toname -
git merge <name>: merge branchnameinto current working branch (normallymaster) -
git merge origin/master: mergeorigin/master, which is the remote version of a repository normally downloaded withgit fetch, into the local, preexistingmasterbranch
Note that git pull is equivalent to running git fetch and then git merge origin/master
GitHub Issues
GitHub's bug tracker is called Issues. It is intended to track bugs, but can also be used to track enhancements, product road-maps, planning, feature requests, etc. It acts as a chatroom/forum/email where all members of your team can communcate about your software project.
Forks
A "fork" of a repository is an entire separate repository which is a copy of the original repository. It can be managed and modified without affecting the original copy.
- Open source projects are developed using forks, and when they want the change to be merged, they submit a "pull request".
Pull Request
Made to merge a branch of a repository with another branch of the same repository or even a different repository. Its a good way to get feedback on changes from collaborators on the same project.
Note: forks issues and pull requests are all github specific features.
Linked from Object-Oriented Software Engineering