Git Research - bounswe/bounswe2024group4 GitHub Wiki

What is git?

Git is basically a version management system for any kind of project. It enables us to keep track of our projects' development through time, try different approaches without messing up our previous work and get back to older states when things go wrong. It also makes us able to work on remote projects with other people via applications such as Github.

How to get started with git?

If your operating system is MacOS or Linux, git is most probably already downloaded in your computer, if you are using windows you can use this command to download git winget install --id Git.Git -e --source winget

How to use git?

To use git you have to use your shell since git works through commands. Below are examples for the most important commands:

Basic commands

  • git init Creates an empty git repository.
  • git add <filename> Adds the file named filename to the staging area
  • git commit -m <message> Commits the files in the staging area to the repository and logs the message
  • git log Prints IDs, authors, commit dates and log messages for all the previous commits

Branching commands

  • git branch Prints the list of current existing branches
  • git branch <new_branch_name> Creates a new branch called new_branch_name
  • git checkout <new_branch> Changes the current working branch as the <new_branch> (specifier can be name or id which is found in logs, using this way one can create a branch from a previous commit).
  • git checkout -b <new_branch_name> Does the combined work of the previous two commands (To learn about branches, you can check the related part below
  • git merge <source_branch> Merges the changes from <source_branch> to the current working branch

Remote management commands

  • git remote add origin <Github_repo_link> Basically connects your local repo to the remote Github repo (origin is the name given to the rmeote repo and actually you can use any word you prefer, but the convention is using the word origin)
  • git push -u origin <branch_name> Sends the specified branch to the remote repository origin
  • git fetch origin Brings all the latest changes from the remote repo to the local repo
  • git pull origin <branch_name> Fetches from the remote repo and also merges to the specified branch

What is a branch?

Branching is a feature of git which enables people to work on a project without messing up the work of others thanks to its tree-like structure. A simple way to explain this is when you create a new branch it is like you create a copy of the same project and whatever you do on this copy does not affect the original project. After you finish your work and test it, you can replace your work with the previous copy.

In git, main branch is called the master branch conventionally and they can be managed with the commands explained above.

⚠️ **GitHub.com Fallback** ⚠️