Version control software allows you to take snapshots of a project whenever it's in a working state when you make changes to a project.
Using version control software gives you the freedom to work on improvements & make mistakes without worrying about ruining your project.
Git is the most popular version control software in use now a day's git implement version control by tracking the changes made to every file in a project; if you make a mistake you can just return to a previously saved state. Git runs on all the Operating System, but there are different approaches to installing it on each system.
To download a git installer from git - downloads. After installing, open a new terminal window & issue the command "git --version." you will see the output listing a specific version number.
Configuring Git:
Git keep's track of who makes changes to a project to do this git needs to know your username & email
$ git config --global user.name "username"
$ git config --global user.email "username@gmail.com"
Making a project:
Create a folder on your system called “git_practice” Inside the folder, make a python program (file)
Hello-git.py
To tell git to ignore this directory, make special file called “.gitignore" with no file extension and add the following line to it: “pychache"
Initialising a repository: -
→a directory containing a python file & .gitignore file, you can initialise a git repository. Open terminal and navigate (cd) to the folder. & run the following: "git init"
→ all the files git uses to manage the repository are located in the hidden directory ".git," which you won't need to work with at all.
Checking the status:
→ let's look at the project's status using "git status"
Adding file to the repository:
Adding the files to the repository using "git add"
Making a commit:
Make the first commit using "git commit -m ". "first commit" (• the -a flag tells git to add all modified file in the repository to current commit
Checking the log:
Git keeps a log of all commits made to the project. Using "git log"
Deleting to repository:
Use the command "rm -rf .git/" to delete the .git directory.
Code snippet to start the git project:
Configuring Git (Set your global username and email)
$ git config --global user.name "your_username"
$ git config --global user.email "your_email@gmail.com"
Create the project folder and the Python file
$ mkdir git_practice
$ cd git_practice
$ touch Hello-git.py # Create the Python file
Create .gitignore to ignore pycache
$ touch .gitignore
$ echo "pycache" >> .gitignore # Add pycache to .gitignore
Initialize the Git repository
$ git init
Check the status of the repository $ git status
Add files to the repository $ git add .
Make your first commit $ git commit -m "first commit"
Check the commit log $ git log
If you want to delete the repository (remove .git directory) $ rm -rf .git/
Conclusion:
Version Control gives you the freedom to work on improvements and mistakes without worrying about your project. We’re then free to use git init to start a fresh repository. Checking the status shows that we’re back at the initial stage, awaiting the first commit. We add the files and make the first commit. Checking the status now shows us that we’re on the main branch with nothing to commit.
Using version control takes a bit of practice, but once you start using it, you’ll never want to work without it again