Keeping track of file versions is hard.
Above all else, Git is a fast version control system, that allows you to efficiently handle projects large and small.
Here are some problems we face as developers, and how git solves them:
Git allows us to make save points at any time. These save points are called 'commits'. Once a save point is made, it's permanent, and allows us to go back to that save point at any time.
Every commit has a description (commit message), which allows us to describe what changes were made between the current and previous commit. This is usually a description of what features were added or what bugs were fixed.
Additionally, git supports tagging, which allows us to mark a specific commit as a specific version of our code (e.g. '2.4.5').
It's often important to see content of the actual changes that were made. This can be useful when:
Git allows us to easily see these changes (called a
diff) for any given commit.
In developing software, we often want to experiment in adding a feature or refactoring (rewriting) existing code. Because git makes it easy to go back to a known good state, we can experiment without worrying that we'll be unable to undo the experimental work.
git initcreates a git repo inside current working directory
git init nameofrepocreates a new folder and a git repo inside that
git add .adds changes from the working directory to the staging area
git add <filename>adds changes to filenames specified from the working directory to the staging area
git commit -m "commit message"adds changes in staging area to the repository
GitHub is a social network that allows developers to host remote repositories. A remote repository is a publicly (sometimes privately) accessible copy of a local repository.
Replace yourusername below with your username when running commands.
test-repoby clicking on the plus sign on the top right.
Clone the repository using the SSH link not the HTTPS link. The command looks like this:
git clone firstname.lastname@example.org:yourusername/test-repo.git
It will say "You appear to have cloned an empty repository."
Add a blank file to the repository using the
touch command. Be sure that you're current working directory (
pwd) is the repository
Edit README.md using your favorite text editor (mine is Sublime Text 3) and add one line with the text, "Hello GA".
git statusto view the changes. You will see one new "Untracked File".
git add README.mdfollowed by
git status. You will see "Changes to be committed" and on the next line "new file: README.md".
git commit -m "initial commit"followed by
git status. You will see "Your branch is up-to-date with 'origin/master'."
git remote -vto see what "origin" is defined as.
git add README.mdand
git commit -m "my second commit"followed by
git statusand then