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 init
creates a git repo inside current working directorygit init nameofrepo
creates a new folder and a git repo inside thatgit status
git add .
adds changes from the working directory to the staging areagit add <filename>
adds changes to filenames specified from the working directory to the staging areagit commit -m "commit message"
adds changes in staging area to the repositorygit log
showsGitHub 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-repo
by 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 git@github.com: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 test-repo
.
touch README.md
Edit README.md using your favorite text editor (mine is Sublime Text 3) and add one line with the text, "Hello GA".
git status
to view the changes. You will see one new "Untracked File".git add README.md
followed 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 push
and git status
. You will see "Your branch is up-to-date with 'origin/master'."git remote -v
to see what "origin" is defined as.git add README.md
and git status
.git commit -m "my second commit"
followed by git status
and then git push
.