--version git
2024-09-09
Before we start:
If not installed
We want to avoid this:
Posted by rjkb041 on r/ProgrammerHumor
This is particularly true when more than one person is collaborating and editing the file.
Even more important when there are multiple files, as there is in software development, and to some extend data analysis.
Posted on devrant.com/ by bhimanshukalra
But we have to learn some things.
From Meme Git Compilation by Lulu Ilmaknun Qurotaini
Note
In these notes, I use < >
to denote a placeholder. So if I say <filename>
what you eventually type is the filename you want to use, without the < >
Sharing.
Collaborating.
Version control.
We focus on the sharing aspects of Git and GitHub, but introduce some of the basics that permit you to collaborate and use version control.
Described a social network for software developers.
Basically, it’s a service that hosts the remote repository (repo) on the web.
This facilitates collaboration and sharing greatly.
There many other features such as
The main tool behind GitHub is Git.
Similar to how the main tool behind RStudio is R.
We are ready to create a GitHub repository (repo).
You will have at least two copies of your code: one on your computer and one on GitHub.
If you add collaborators to this repo, then each will have a copy on their computer.
The GitHub copy is considered the main (previously called master) copy that everybody syncs to.
Git will help you keep all the different copies synced.
Let’s go make one on GitHub…
Then create a directory on your computer, this will be the local repo, and connect it to the Github repository.
First copy and paste the location of your git repository. It should look something like this:
https://github.com/your-username/your-repo-name.git
When accessing GitHub you need credentials to verify your identity.
There are two ways to connect: HTTPS or SSH, each requiring different credentials.
We recommend using HTTPS, which uses a Personal Access Token (PAT).
Note that your GitHub website password isn’t your access token.
Detailed instructions are here.
Carefully follow the instructions provided by GitHub.
When setting permissions for the token, choose non-expiring and select the repo option in the scopes section.
Once you complete these steps, GitHub will display your token—a lengthy string of characters.
Immediately copy this token to your clipboard. This is the only time GitHub will show it to you.
For security, save this token in a password manager. This ensures you can access it if needed later on.
When git prompts you to enter your password, paste the token you’ve copied. After this, password prompts should no longer appear.
If you ever need the token again, retrieve it from your password manager.
More details available from Happy Git and GitHub for the use.
The next step is to let Git know who we are on Github.
To to this type the following two commands in our terminal window:
This will change the Git configuration in way that anytime you use Git, it will know this information.
Note that you need to use the email account that you used to open your GitHub account.
To connect working directory to the GitHub repo
Now the two are connected.
Note
origin
is a nickname we will use for the remote. We can call it something else, but everybody calls it origin so best to stick with that.
The main actions in Git are to:
From Meme Git Compilation by Lulu Ilmaknun Qurotaini
Use git add
to put file to staging area.
We say that this file has been staged. Check to see what happened:
git commit
.Once committed the files are tracked and a copy of this version is kept going forward.
This is like adding V1
to your filename.
Note
You can commit files directly without using add
by explicitely writing the files at the end of the commit:
git push
The -u
flag sets the upstream repo.
By using this flag, going forward you can simply use git push
to push changes.
So going forward we can just type:
When using git push
we need to be careful as if collaborating this will affect the work of others.
It might also create a conflict
.
Posted by andortang on Nothing is Impossible!
I rarely use fetch
and merge
and instead use pull
which does both of these in one step
Warning
If you have a newer version in your local repository this will create a conflict. It won’t let you do it. If you are sure you want to get rid of your local copy you can remove it and then use checkout
.
checkout
to obtain older version:commit-id
either on the GitHub webpage or usingundos the commit and unstages the files, but keeps your local copies. I use this on very often.
There are many wasy of using get reset
and it covers most scenarios.
ChatGPT and stackoverflow are great resources to learn more.
We are just sratching the surface of Git.
One advanced feature to be aware of is that you can have several branches, useful for working in parallel or testing stuff out that might not make the main repo.
Art by: Allison Horst
Another common command is git clone
.
It let’s download an entire repo, including version history.
Go to file, new project, version control, and follow the instructions.
Then notice the Git
tab in the preferences.
From Meme Git Compilation by Lulu Ilmaknun Qurotaini
For more memes see Meme Git Compilation by Lulu Ilmaknun