What Is Git?
Git is an open-source version control system which means that it records files over a period of time and these changes can be recalled at a later date. You can do a lot with Git whether it can be branching (creating something that is different from the master branch (the one you would most likely be working on)) or just committing to a repository (programming jargon simply calls it a repo).
Basic Setup
Depending on what OS (operating system) you have the setup might be slightly different.
Linux :
sudo apt update This will essentially update your system.
sudo apt install git This will install Git on the system.
git --version This is used to verify its downloaded.
Windows:
Navigate to Git-SCM: Git SCM Download
Git SCM will download protocol but also a BASH, a command line
Basic/ Most Used Bash Commands
ls - lists the folders and files in the working directory (the current directory you are in)
cd - changes directory
pwd- used to find the path for the current directory
mkdir- make a directory
touch - update the access and or modification date of a file or directory without opening, saving or closing the file.
cat - print files to stdout
mv - moves files and folders
cp - copies files or folders
rm - remove files and folder (look into modifiers for this one)
chmod - Change mode so you can set permissions for read, write and execute for the user, members of your group and others. (Binary can be used for this)
man - can be used to look up any commands ie man cd
Using GitBash/Terminal to Access GitHub
Configure Git via git config --global user.name "[name]" and git config --global user.email "[email address]"
Navigate to your working directory
Initialize a Git Repo via git init
Now, this is where you can branch-of, you have two options, -------pushing a new repo or pushing a preexistent repo.
- Pushing a New Repo
Commit your repo via git commit -m "first commit"
Remote add your repo via git remote add origin <url>
Push to your repo via git push -u origin master
- For Pushing an Existing Repo
Remote add your repo via git remote add origin <url>
Push to your repo via git push -u origin master
Now that you have your repo set up, these are some helpful commands:
git status Used to check what has changed ie additions and deletions
git add <file> Used to add files to commit if used with a period (.) it adds all of the files
git commit -m "message" Use to commit changed, but it is on the local system, the -m can be changed to things such as -u which is an update but it is recommended to keep with an -m
git push Used to push changes to GitHub
git reset Can be used after commit to reset the commits (Good if you accidentally add a file you did not want)
git pull <url> Can be used to pull from any git repo, leave the URL out if your updating your current repo
.gitignore
The .gitignore file is useful for stopping certain files from committing automatically. It should automatically be in a repo when you create a project. To use it just cd to the directory where the file you want to exclude is and use pwd to find the directory pathing. Then copy the path into the file, it should look like a text file, and then add the name of the file you want to exclude.
Example: User/Jill/Programming/src/JillNandaha
Branching in Git
Branching is useful when many people are working on the same project or when you have multiple versions of the same project. The major advantage of branching is when you want to add a feature without compromising the integrity of the master branch.
Branching Commands
git branch [branch-name] Used to create a new branch
git checkout [branch-name] Used to switch branches
git merge [branch] Used to merge branch commits
git branch -d [branch-name] Used to delete a branch
The relevance of Git Bash extends beyond version control, as it plays a critical role in standardizing development environments and enhancing developer productivity. By providing a consistent command-line interface, Git Bash allows scripts, build processes, and automation tasks to be executed uniformly across different operating systems. Proficiency in Git Bash strengthens a developer’s understanding of system-level operations and prepares them for working with advanced tools such as Docker, CI/CD pipelines, and remote servers that rely heavily on Unix-based command-line interactions.
Top comments (0)