Git for Windows and run it. The configurations can be set to its default.
Simply use the package manager of your distro. e.g.
$ sudo apt-get install git
$ sudo yum install git
Now that Git is installed, you can start using it from the command line interface. Type
git and hit enter.
Now before we discuss any of the commands above, let’s talk about what is a repository first.
Repository — or repo for short, is a directory or folder that tracks every file that exist on its parent folder. Think of repo as a kind of database where all changes of your file is being tracked. In Git, a repo is generated by using the command
git init. A hidden folder named
.git will appear in the directory where you run the command.
Let’s created a file into our initialized repo
$ echo "Hello World" > README.txt
git status and you’ll see that an untracked file will appear.
Staging area — is where a file is being added, but not yet committed into Git repository.
In order to make Git track the README.txt file, run the command
git add README.txt
If you are adding a wrong file, you can remove it from staging by running
git reset README.txt. For now, let’s commit this README.txt file
Commit is taking a snapshot of all files put into the staging area at the time the command is run. This will be a checkpoint and permanently save a record in Git. You need to add a short message describing the commit, or it will fail to run.
Run a commit by using
git commit -m
$ git commit -m 'My first commit'
All files in the staging area will be committed, and
git status will show there is nothing to commit. We can run
git log to check on history of commits in the repo.
Congratulations on your first commit! Let’s take a short break and move on to explore branching
I'm sending out an email once every Wednesday with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!