Essential Git Commands for Data Scientists

Git is a powerful versioning control system that helps you to track changes in your codebase, collaborate and manage your project’s history. most of the data scientists are unaware of software development tools such as version control systems like git. modern data scientists use it to collaborate on codebase projects and resolve conflicts faster very easily. In this post, we will learn some essential Git commands that will help you initialize a project, Configuring git, create branches it with a remote server and monitor the changes.

1. Initialization

Initialize a new Git repository in the current directory.

git init

Or you can initialize Git repository in a specific directory.

git init <directory>

2. Clone

The clone command will copy all of the remote server project files to the local machine. It also add a remote name as origin to sync files with the remote server. Git clone requires secure connection SSH link.

git clone <HTTPS/SSH>

Example :

3. Adding Remote

git can able to connect with single or multiple remote servers by adding the name of the remote and HTTPS/SSH address.

git remote add <remote name> <HTTPS/SSH>

git remote add origin [repository_url]

4. View Remote

git can provide command to see view remote repositories with below command.

git remote -v

5. Create Branch

Branches are the best way to work on a new feature of the code. It allows you to work without disturbing the `main` branch. create a new branch with the checkout command with ‘-b’ tag and the branch name. 

git checkout -b <branch-name>

Or use switch with ‘-c’ tag with branch name.

git switch -c <branch-name>

Or simply you can use branch command.

git branch <branch-name>

6. Switch Branch

in git if you want to switch a branch from current to a different branch, you can use the checkout or switch command followed by branch name.

git checkout <branch-name>

git switch <branch-name>

7. Pull

if you want to synchronize changes with a remote server so you need to first pull changes from the remote to the local repository by using the pull command. it will required when changes are made in a remote repository.  

git pull

You can add remote name followed by a branch name to pull a single branch. 

git pull <remote name> <branch>

8. Add

if you want to add files into the staging area so It requires the filename or list of file names.

git add <file-name>

You can also add all files using the ‘.’ flag. 

git add .

9. Commit

If you added files to the staging area so you can create a version by using the commit command. The commit requires the title of the commit by using the ‘-m’ flag. If you made changes and want to list all, add them to the description by using another ‘-m’.

git commit -m "This is testing message"

Note : you need to make sure you have configured/setup your username and email before commit changes to git.

10. Configuring Git

you need to setup your global Git username with below command.

git config --global user.name "Your Name"

if you want to check username so you can check below command.

git config --global user.name

you need to setup your global Git email with below command.

git config --global user.email "[email protected]"

if you want to check email so you can check below command.

git config --global user.email

11. Push

if you want to synchronize local changes to remote servers using the push command or you want to upload changes to remote server using the push command. pushing changes to a specific remote server and branches to use the command below. 

git push <remote name> <branch-name>

Leave a Reply

Your email address will not be published. Required fields are marked *

− 2 = 6