Skip to content

BAcode-X/ASTU-FSE-Git-Guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ASTU-FSE-Git-Guide

A simple guide for learning Git

Before jumping into the code, let's first try to cover some common terminologies related to version control.

1. Version Control System :

allows you to revert files back to a previous state, revert the entire project back to a previous state, review changes made over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

2. Repository :

directory that contains your project work which are used to communicate with Git. Repositories can exist either locally on your computer or as a remote copy on another computer.

3. Commit :

Git thinks of its data like a set of snapshots of a mini file system. Think of it as a save point during a video game.

4. SHA :

A SHA is basically an ID number for each commit. Ex. E2adf8ae3e2e4ed40add75cc44cf9d0a869afeb6

5. Working Directory :

The files that you see in your computer's file system. When you open your project files up on a code editor, you're working with files in the Working Directory.

6. Checkout :

When content in the repository has been copied to the Working Directory. It is possible to checkout many things from a repository; a file, a commit, a branch, etc.

7. Staging Area :

You can think of the staging area as a prep table where Git will take the next commit. Files on the Staging Index are poised to be added to the repository.

8. Branch :

it is when a new line of development is created that diverges from the main line of development. This alternative line of development can continue without altering the main line.

Git has three sections/areas

Next, if you haven't installed git on your computer :

For windows users, install git bash from the following link : Download Git

For linux users, run the following command on the terminal : sudo apt-get install git

To set the name and email for git to use when you commit use the following command :

git config --global user.name "<your name>"
git config --global user.email "<your email>"

Go to your github account and click the button New, which is a button for creating a new repository. Then give it a name and click on the create repository button.

Now copy the url and open the terminal and enter the following command

git clone <url> [local dir name]

This will create a directory named , containing a working copy of the files from the repo, and a .git directory

Now you can start adding and commiting changes to your repository.

Create a sample python file and name it test

touch test.py

To check about the status of your working directory, use the following command.

git status

Go ahead and try the command now. It will tell you that there is an untracked file and asks you to add the file using the add command.

To add new files or changed files into the staging area use the add command

git add <filename> in your case, git add test.py

To add all new files you have created to the staging area, use the following command

git add .

To commit the staged files, use the commit command followed by a message

git commit -m "<message>" in your case, git commit -m "added test.py"

The message part is to describe what kind of change you have made to your directory or code.

Now check the status of your working directory using the status command.
You should be seeing "nothing to commit, working directory clean" message.

While working on your project there might be files which contain credentials and some other sensitive informations that you don't want to share to everyone.

For example, lets create a simple txt file with a name password. touch password.txt

Lets assume this password.txt file contains a secret information and you don't want Git to track it.

To make git NOT track specific files, create a .gitignore file and add the file name in it using ur prefered text editor.

touch .gitignore

Now open the file in any editor and write password.txt on the first line of the file. Then use the add and commit command to save the changes you made.

Note that when you use add, it didn't track the password.txt file.

If you wish to make git not track all of txt files, you can add '*.txt' (without the quote) on the .gitignore file.

About

A simple guide for learning Git

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors